Add GICv3 SGI boot/self tests in Xen
PATCH v2 1/1 Add GICv3 SGI boot/self tests in Xen
Boot self-tests (also referred to as boot-time tests or power-on self-tests) are intended to validate internal features of Xen during bring-up. They are meant to be run in a debug / validation environment; Xen is not expected to remain functional for production use after the self-tests have executed. The purpose of these tests is to catch hardware configuration issues early and to confirm that the platform on which Xen has been brought up is sane. The expected flow is:
build Xen with the self-tests enabled, boot it, inspect the results, and then reboot into the usual production configuration.
Introduce the tests to confirm that:
1. A cpu can send SGI 0 to itself
2. A cpu can send SGI 0 to another specific CPU
3. A cpu can send SGI 0 to all the other CPUs
4. A cpu can send SGI 1 to another CPU
These tests aim to test Xen has configured the GIC correctly to use SGIs. Thus, the tests invoke specific APIs of GIC driver.
Also, introduce a config CONFIG_BOOT_SELFTEST which enables these tests. The option defaults to N; it should be disabled for production builds and is intended for the validation pipeline and coverage measurement. The tests run during Xen boot and validate internal interfaces such as Xen's interface with hardware, firmware and the bootloader.
Also, introduce an integer command line parameter "gic-test". By default, it is set to 0 which means no tests are enabled.
For running SGI tests, "gic-test" should be set to 1. In future if we add tests for distributer, ITS, LPI, etc, then we can use different numbers. Thus, each number denotes a functionality of GICv3 which can be tested independently and within a single boot of Xen.
In this way, we ensure that the tests to validate SGIs do not impact any other tests.
In order to keep all the boot-time self-tests together in the binary, we have introduced a separate section "initcallboottest". All the tests are registered using __initcallboottest. During the bootup of each core, Xen invokes do_init_boottests() to run the these tests. All these tests are invoked before Xen creates the domains (in case of primary core) or runs the idle loop (in case of secondary core).
Note: it was suggested that, once the boot self-tests have run, Xen should call machine_halt() rather than continue booting (since this build is only intended for validation). This is not wired in here because the SGIs are sent from the primary and secondary CPUs and received asynchronously on the target CPUs. There is no definite point in the boot flow at which Xen can know that every send has been observed by its receiver, so "after the tests have completed" has no well-defined moment at which to insert machine_halt().
---
Link to v1 (RFC):
https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00956.html
Upstream CI run (xen-project/people/ayankuma/xen fork, one commit on top of xen-project/xen staging — all Linux builds + tests including qemu-smoke-boot-selftest-arm64-gcc-debug passed; only the macos jobs sit pending because the personal fork has no macos runner):
https://gitlab.com/xen-project/people/ayankuma/xen/-/pipelines/2561806695
Changes in v2:
- Renamed the patch from "xen/arm: Introduce GICV3 Self Tests" to "Add GICv3 SGI boot/self tests in Xen", and rewrote the commit message to explain the intent of boot self-tests (debug / validation builds only, Xen not expected to remain functional afterwards).
- Moved the selftest code out of gic-v3.c into a dedicated file xen/arch/arm/gic-test.c, gated by CONFIG_BOOT_SELFTEST (Stefano, Grygorii).
- Introduced a generic boot-self-test framework: new section "initcallboottest", registration macro __initcallboottest, and do_init_boottests() invoked once per CPU after local_irq_enable(), so the test runs on every CPU (boot + secondaries) and no longer collides with the IRQ-enable timing in gicv3_init() (Julien #1, Julien #3).
- Added Kconfig option CONFIG_BOOT_SELFTEST in xen/arch/arm/Kconfig (arm-only for now; arch-specific because the only registered test is GICv3-specific).
- Reserved a dedicated SGI value GIC_SGI_TEST in enum gic_sgi (xen/arch/arm/include/asm/gic.h), so the selftest never reuses a functional SGI (Grygorii #3).
- Added a runtime integer command-line parameter "gic-test" so the selftest binary can be shipped but its execution selected at boot (gic-test=0 -> no-op; gic-test=1 -> SGI tests). Future GICv3 features (distributor, ITS, LPI, ...) can claim further values (Grygorii #2, partial).
- Documented why machine_halt() is not invoked after the tests:
SGI delivery is asynchronous, so there is no well-defined point after which every send has been observed by its receiver (Julien #2).
- Wired the tests into upstream GitLab CI: new build job alpine-3.18-gcc-debug-arm64-boot-selftest, new test job qemu-smoke-boot-selftest-arm64-gcc-debug, and the runner script automation/scripts/qemu-boot-selftest-arm64.sh that dumps the QEMU virt DTB, injects
"gic-test=1 console=dtuart sync_console" into /chosen/xen,xen-bootargs via fdtput, boots Xen, and checks for each "Sending GIC_SGI_TEST ..." followed by the matching "CPU%u: GIC_SGI_TEST received".
automation/gitlab-ci/build.yaml | 8 ++ automation/gitlab-ci/test.yaml | 8 ++ .../scripts/qemu-boot-selftest-arm64.sh | 81 +++++++++++++++++++ xen/arch/arm/Kconfig | 15 ++++ xen/arch/arm/Makefile | 1 + xen/arch/arm/gic-test.c | 52 ++++++++++++ xen/arch/arm/gic.c | 5 ++ xen/arch/arm/include/asm/gic.h | 3 + xen/arch/arm/setup.c | 2 + xen/arch/arm/smpboot.c | 2 + xen/arch/arm/xen.lds.S | 4 + xen/common/kernel.c | 11 +++ xen/include/xen/init.h | 3 + 13 files changed, 195 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
@@ -439,6 +439,14 @@ alpine-3.18-gcc-debug-arm64: CONFIG_UBSAN=y CONFIG_UBSAN_FATAL=y +alpine-3.18-gcc-debug-arm64-boot-selftest: + extends: .gcc-arm64-build-debug + <<: *build-test + variables: + CONTAINER: alpine:3.18-arm64v8 + EXTRA_XEN_CONFIG: | + CONFIG_BOOT_SELFTEST=y + alpine-3.18-gcc-arm64-randconfig: extends: .gcc-arm64-build variables:
automation/gitlab-ci/test.yaml +8 -0
@@ -524,6 +524,14 @@ qemu-smoke-dom0less-arm64-gcc-debug-gicv3: - *arm64-test-needs - alpine-3.18-gcc-debug-arm64 +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.18-gcc-debug-arm64-boot-selftest + qemu-smoke-dom0less-arm64-gcc-debug-staticmem: extends: .qemu-arm64 script:
automation/scripts/qemu-boot-selftest-arm64.sh new file +81 -0
81 lines not on this page · raw message
xen/arch/arm/Kconfig +15 -0
@@ -476,6 +476,21 @@ 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-time self-tests" + default n + help + This option enables boot-time self-tests that validate Xen's internal + interfaces with hardware, firmware and the bootloader. The tests are + registered with __initcallboottest and executed by do_init_boottests() + during early boot, before domains are created. + + These tests are intended for validation and coverage measurement, not + for production builds. With this option enabled, Xen may not be + functional after the tests have run. + + 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.init.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 +52 -0
52 lines not on this page · raw message
xen/arch/arm/gic.c +5 -0
@@ -324,6 +324,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 : +printk ("CPU%u: GIC_SGI_TEST received\n" ,smp_processor_id ()); +break ; +#endif default :panic ("Unhandled SGI %d on CPU%d\n" , sgi,smp_processor_id ());break ;
xen/arch/arm/include/asm/gic.h +3 -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, };
xen/arch/arm/setup.c +2 -0
@@ -470,6 +470,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 +2 -0
@@ -405,6 +405,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)
xen/common/kernel.c +11 -0
@@ -412,6 +412,7 @@ void add_taint(unsigned int taint)extern const initcall_t __initcall_start[], __presmp_initcall_end[], __initcall_end[]; +extern const initcall_t __initcall_boot_test_start[], __initcall_boot_test_end[];void __init do_presmp_initcalls (void ) {
@@ -427,6 +428,16 @@ void __init do_initcalls(void) (*call)(); } +void __init do_init_boottests (void ) +{ +#ifdef CONFIG_BOOT_SELFTEST +const initcall_t *call; +for ( call = __initcall_boot_test_start; call < __initcall_boot_test_end; + call++ ) + (*call)(); +#endif +} +#ifdef CONFIG_HYPFS static unsigned int __read_mostly major_version;static unsigned int __read_mostly minor_version;
xen/include/xen/init.h +3 -0
@@ -66,11 +66,14 @@ typedef void (*exitcall_t)(void); static const initcall_t __initcall_##fn __init_call("presmp") = (fn)#define __initcall (fn) \ static const initcall_t __initcall_##fn __init_call("1") = (fn) +#define __initcallboottest (fn) \ + static const initcall_t __initcall_##fn __init_call("boottest") = (fn)#define __exitcall (fn) \ static exitcall_t __exitcall_##fn __exit_call = fnvoid do_presmp_initcalls (void );void do_initcalls (void ); +void do_init_boottests (void );#endif /* __ASSEMBLER__ */
Signature · 1 line
2.25.1
Hi Ayan,
Quoted 5 lines · Ayan Kumar Halder
Boot self-tests (also referred to as boot-time tests or power-on self-tests) are intended to validate internal features of Xen during bring-up. They are meant to be run in a debug / validation environment; Xen is not expected to remain functional for production use after the self-tests have executed.
Looking at the code below, isn't Xen functional even after the self-test?
Quoted 11 lines
The purpose of these tests is to catch
hardware configuration issues early and to confirm that the platform on which Xen has been brought up is sane. The expected flow is:
build Xen with the self-tests enabled, boot it, inspect the results, and then reboot into the usual production configuration.Introduce the tests to confirm that:
1. A cpu can send SGI 0 to itself
2. A cpu can send SGI 0 to another specific CPU
3. A cpu can send SGI 0 to all the other CPUs
4. A cpu can send SGI 1 to another CPU
I am not sure what you meant by SGI 0 and SGI 1? Below you seem to be use only a SGI (which is neither 0 or 1) except for one specific test: cpu 0 injecting an SGI to a specific CPU (0).
Quoted 174 lines
These tests aim to test Xen has configured the GIC correctly to use SGIs. Thus, the tests invoke specific APIs of GIC driver.
Also, introduce a config
CONFIG_BOOT_SELFTESTwhich enables these tests. The option defaults to N; it should be disabled for production builds and is intended for the validation pipeline and coverage measurement. The tests run during Xen boot and validate internal interfaces such as Xen's interface with hardware, firmware and the bootloader.Also, introduce an integer command line parameter "gic-test". By default, it is set to 0 which means no tests are enabled.
For running SGI tests, "gic-test" should be set to 1. In future if we add tests for distributer, ITS, LPI, etc, then we can use different numbers. Thus, each number denotes a functionality of GICv3 which can be tested independently and within a single boot of Xen.In this way, we ensure that the tests to validate SGIs do not impact any other tests.
In order to keep all the boot-time self-tests together in the binary, we have introduced a separate section "initcallboottest". All the tests are registered using
__initcallboottest. During the bootup of each core, Xen invokesdo_init_boottests()to run the these tests. All these tests are invoked before Xen creates the domains (in case of primary core) or runs the idle loop (in case of secondary core).Note: it was suggested that, once the boot self-tests have run, Xen should call
machine_halt()rather than continue booting (since this build is only intended for validation). This is not wired in here because the SGIs are sent from the primary and secondary CPUs and received asynchronously on the target CPUs. There is no definite point in the boot flow at which Xen can know that every send has been observed by its receiver, so "after the tests have completed" has no well-defined moment at which to insertmachine_halt().Signed-off-by Ayan Kumar Halder <[email protected]>Signed-off-by Michal Orzel <[email protected]>---
Link to v1 (RFC):
https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00956.htmlUpstream CI run (xen-project/people/ayankuma/xen fork, one commit on top of xen-project/xen staging — all Linux builds + tests including qemu-smoke-boot-selftest-arm64-gcc-debug passed; only the macos jobs sit pending because the personal fork has no macos runner):
https://gitlab.com/xen-project/people/ayankuma/xen/-/pipelines/2561806695Changes in v2:
- Renamed the patch from "xen/arm: Introduce GICV3 Self Tests" to "Add GICv3 SGI boot/self tests in Xen", and rewrote the commit message to explain the intent of boot self-tests (debug / validation builds only, Xen not expected to remain functional afterwards).
- Moved the selftest code out ofgic-v3.cinto a dedicated filexen/arch/arm/gic-test.c, gated byCONFIG_BOOT_SELFTEST(Stefano, Grygorii).
- Introduced a generic boot-self-test framework: new section "initcallboottest", registration macro__initcallboottest, anddo_init_boottests()invoked once per CPU afterlocal_irq_enable(), so the test runs on every CPU (boot + secondaries) and no longer collides with the IRQ-enable timing ingicv3_init()(Julien #1, Julien #3).
- AddedKconfigoptionCONFIG_BOOT_SELFTESTin xen/arch/arm/Kconfig (arm-only for now; arch-specific because the only registered test is GICv3-specific).
- Reserved a dedicated SGI valueGIC_SGI_TESTin enumgic_sgi(xen/arch/arm/include/asm/gic.h), so the selftest never reuses a functional SGI (Grygorii #3).
- Added a runtime integer command-line parameter "gic-test" so the selftest binary can be shipped but its execution selected at boot (gic-test=0 -> no-op; gic-test=1 -> SGI tests). Future GICv3 features (distributor, ITS, LPI, ...) can claim further values (Grygorii #2, partial).
- Documented whymachine_halt()is not invoked after the tests:
SGI delivery is asynchronous, so there is no well-defined point after which every send has been observed by its receiver (Julien #2).
- Wired the tests into upstream GitLab CI: new build job alpine-3.18-gcc-debug-arm64-boot-selftest, new test job qemu-smoke-boot-selftest-arm64-gcc-debug, and the runner scriptautomation/scripts/qemu-boot-selftest-arm64.shthat dumps the QEMU virt DTB, injects
"gic-test=1 console=dtuartsync_console" into /chosen/xen,xen-bootargs via fdtput, boots Xen, and checks for each "SendingGIC_SGI_TEST..." followed by the matching "CPU%u:GIC_SGI_TESTreceived".automation/gitlab-ci/build.yaml | 8 ++ automation/gitlab-ci/test.yaml | 8 ++ .../scripts/qemu-boot-selftest-arm64.sh | 81 +++++++++++++++++++ xen/arch/arm/Kconfig | 15 ++++ xen/arch/arm/Makefile | 1 + xen/arch/arm/gic-test.c | 52 ++++++++++++ xen/arch/arm/gic.c | 5 ++ xen/arch/arm/include/asm/gic.h | 3 + xen/arch/arm/setup.c | 2 + xen/arch/arm/smpboot.c | 2 + xen/arch/arm/xen.lds.S | 4 + xen/common/kernel.c | 11 +++ xen/include/xen/init.h | 3 + 13 files changed, 195 insertions(+)create mode 100755
automation/scripts/qemu-boot-selftest-arm64.shcreate mode 100644xen/arch/arm/gic-test.cautomation/gitlab-ci/build.yaml +8
-0@@ -439,6 +439,14 @@ alpine-3.18-gcc-debug-arm64: CONFIG_UBSAN=y CONFIG_UBSAN_FATAL=y +alpine-3.18-gcc-debug-arm64-boot-selftest: + extends: .gcc-arm64-build-debug + <<: *build-test + variables: + CONTAINER: alpine:3.18-arm64v8 + EXTRA_XEN_CONFIG: | + CONFIG_BOOT_SELFTEST=y + alpine-3.18-gcc-arm64-randconfig: extends: .gcc-arm64-build variables:automation/gitlab-ci/test.yaml +8
-0@@ -524,6 +524,14 @@ qemu-smoke-dom0less-arm64-gcc-debug-gicv3: - *arm64-test-needs - alpine-3.18-gcc-debug-arm64 +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.18-gcc-debug-arm64-boot-selftest + qemu-smoke-dom0less-arm64-gcc-debug-staticmem: extends: .qemu-arm64 script:automation/scripts/qemu-boot-selftest-arm64.sh new file +25
-0@@ -0,0 +1,81 @@ +#!/bin/bash + +set -ex -o pipefail + +# Boot the prebuilt Xen binary under QEMU with CONFIG_BOOT_SELFTEST=y enabled +# and gic-test=1 in xen,xen-bootargs, then verify the four GICv3 SGI self-tests +# pass by inspecting the serial log. + +XEN=binaries/xen +QEMU=./binaries/qemu-system-aarch64 +DTB_RAW=binaries/virt.dtb +DTB=binaries/virt-bootselftest.dtb +LOG=smoke.serial + +test -x ${QEMU} +test -f ${XEN} + +# Dump the auto-generated DT from the QEMU virt machine, then inject +# /chosen/xen,xen-bootargs. The selftest infrastructure invokes +# do_init_boottests() during early boot; gic-test=1 selects the GICv3 SGI +# tests. +# -net none avoids QEMU's default virtio-net-pci, whose efi-virtio.rom +# is not shipped with the qemu-system-aarch64 artifact used in CI. +${QEMU} \ + -machine virt,virtualization=true,gic-version=3,dumpdtb=${DTB_RAW} \
automation/scripts/qemu-boot-selftest-arm64.sh line 35
Quoted 10 lines
automation/scripts/qemu-boot-selftest-arm64.sh new file +10
-0+ -cpu cortex-a57 -m 1024 -smp 2 -display none -net none + +cp ${DTB_RAW} ${DTB} +fdtput -t s ${DTB} /chosen xen,xen-bootargs \ + "gic-test=1 console=dtuart sync_console" + +rm -f ${LOG} +timeout 60 ${QEMU} \ + -machine virt,virtualization=true,gic-version=3 \ + -cpu cortex-a57 -m 1024 -smp 2 \
This means that there is no much difference between "send an SGI to a specific CPU" and "send an SGI to others CPU". I think it would be more meaningful to use 3 or more pCPUs.
Quoted 51 lines
automation/scripts/qemu-boot-selftest-arm64.sh new file +46
-0+ -serial file:${LOG} \ + -monitor none -display none -no-reboot -net none \ + -dtb ${DTB} \ + -kernel ${XEN} || true + +# Each "Sending GIC_SGI_TEST ..." line must be followed by the matching +# "CPU%u: GIC_SGI_TEST received". +fail=0 +check_pair() { + local send_pat=$1 + local recv_pat=$2 + local send_line recv_line + + send_line=$(grep -n -- "${send_pat}" ${LOG} | head -n1 | cut -d: -f1) + if [ -z "${send_line}" ]; then + echo "MISSING: ${send_pat}" + fail=1 + return + fi + + recv_line=$(grep -n -- "${recv_pat}" ${LOG} \ + | awk -v bl="${send_line}" -F: '$1 > bl {print $1; exit}') + if [ -z "${recv_line}" ]; then + echo "MISSING (after line ${send_line}): ${recv_pat}" + fail=1 + return + fi + + echo "OK: '${send_pat}' -> '${recv_pat}' (lines ${send_line} -> ${recv_line})" +} + +# Boot CPU sends SGI to itself +check_pair "Sending GIC_SGI_TEST to self CPU0" "CPU0: GIC_SGI_TEST received" +# Secondary CPU sends SGI to itself +check_pair "Sending GIC_SGI_TEST to self CPU1" "CPU1: GIC_SGI_TEST received" +# Secondary CPU sends SGI to primary +check_pair "Sending GIC_SGI_TEST to CPU0 from CPU1" "CPU0: GIC_SGI_TEST received" +# Send to all-but-self +check_pair "Sending GIC_SGI_TEST to all except CPU1" "CPU0: GIC_SGI_TEST received" + +if [ ${fail} -ne 0 ]; then + echo "FAILED" + exit 1 +fi + +echo "PASSED"xen/arch/arm/Kconfig +0
-0
xen/arch/arm/Kconfig config ARM64_HARDEN_BRANCH_PREDICTOR · line 481
Quoted 6 lines
xen/arch/arm/Kconfig +3
-0@@ -476,6 +476,21 @@ 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-time self-tests" + default n
Above you said, this is not meant for production. So I was expecting to see a dependency on CONFIG_DEBUG.
If the intention is to use it in release build, given the current behavior (e.g. breaking test), I think this should depend on UNSUPPORTED so we don't get security report because Xen is broken after the boot tests.
xen/arch/arm/Kconfig config ARM64_HARDEN_BRANCH_PREDICTOR · line 490
Quoted 8 lines
xen/arch/arm/Kconfig +8
-0+ help> + This option enables boot-time self-tests that validate Xen's internal + interfaces with hardware, firmware and the bootloader. The tests are + registered with __initcallboottest and executed by do_init_boottests() + during early boot, before domains are created. + + These tests are intended for validation and coverage measurement, not + for production builds. With this option enabled, Xen may not be + functional after the tests have run.
If we know a test break, I think it is best that Xen doesn't continue. Otherwise, it is quite confusing for the user to know what's going on.
My preference is the bootest would act like other self tests and Xen can continue booting normally. So the tests could also be meaningful in non-test setups.
Quoted 24 lines
xen/arch/arm/Kconfig +3
-0+ + 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.init.o obj-$(CONFIG_GICV2) += gic-v2.o obj-$(CONFIG_GICV3) += gic-v3.o obj-$(CONFIG_HAS_ITS) += gic-v3-its.oxen/arch/arm/gic-test.c new file +0
-0
xen/arch/arm/gic-test.c line 6
Quoted 6 lines
xen/arch/arm/gic-test.c new file +6
-0@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/delay.h> +#include <xen/init.h> +#include <xen/param.h> +#include <xen/shutdown.h>
Can you clarify why you need this header?
xen/arch/arm/gic-test.c line 15
Quoted 9 lines
xen/arch/arm/gic-test.c new file +9
-0+#include <asm/gic.h> + +/* +* gic_test: Specifies the gic test to be executed. +* 0 = no tests are executed +* 1 = SGI tests are executed +*/ +static unsigned int __initdata gic_test =0 ; +integer_param ("gic-test" , gic_test);
Given this is mean to be 0 or 1, why not using "boolean_param"?
Also, new command line option should be documented in the docs. That said, I am not really sure about
Quoted 9 lines
xen/arch/arm/gic-test.c new file +9
-0+ +/* +* CPU0: GIC_SGI_DUMP_STATE to self +* CPU{0-N}: GIC_SGI_TEST to self +* CPU{1-N}: GIC_SGI_TEST to CPU0 +* CPU{N}: GIC_SGI_TEST to all but self +*/ +static int __init gic_self_sgi_test (void ) +{
xen/arch/arm/gic-test.c line 34
Quoted 10 lines
xen/arch/arm/gic-test.c new file +10
-0+if ( !gic_test ) +return 0 ; + +printk ("Sending GIC_SGI_TEST to self CPU%u\n" ,smp_processor_id ()); +send_SGI_self (GIC_SGI_TEST ); + +if (smp_processor_id () ==0 ) + { +printk ("Sending GIC_SGI_DUMP_STATE to CPU0\n" ); +smp_send_state_dump (0 );
OOI, why is this only called for CPU0? You also don't seem to check that smp_send_state_dump() in the CI test.
xen/arch/arm/gic-test.c line 43
Quoted 9 lines
xen/arch/arm/gic-test.c new file +9
-0+ +return 0 ; + } + +printk ("Sending GIC_SGI_TEST to CPU0 from CPU%u\n" ,smp_processor_id ()); +send_SGI_one (0 ,GIC_SGI_TEST ); + +/* Execute this test only from the last core */ +if (smp_processor_id () == (smp_get_max_cpus () -1 ) )
This is relying on how Xen is boot CPUs. Would it be better to check the number of online CPUs at the time of the check? (You might need to re-order some code for that)
Quoted 14 lines
xen/arch/arm/gic-test.c new file +9
-0+ { +printk ("Sending GIC_SGI_TEST to all except CPU%u\n" ,smp_processor_id ()); +send_SGI_allbutself (GIC_SGI_TEST ); + } + +return 0 ; + +} +__initcallboottest (gic_self_sgi_test);xen/arch/arm/gic.c +0
-0
xen/arch/arm/gic.c static void do_static_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi) · line 329
Quoted 6 lines
xen/arch/arm/gic.c +3
-0@@ -324,6 +324,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 : +printk ("CPU%u: GIC_SGI_TEST received\n" ,smp_processor_id ());
To confirm, we will solely rely on logging? IOW, there is no plan to have Xen self-sufficient (e.g. using a global variable).
Quoted 73 lines
xen/arch/arm/gic.c +2
-0+break ; +#endif default :panic ("Unhandled SGI %d on CPU%d\n" , sgi,smp_processor_id ());break ;xen/arch/arm/include/asm/gic.h +3
-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, };xen/arch/arm/setup.c +2
-0@@ -470,6 +470,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 +2
-0@@ -405,6 +405,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)xen/common/kernel.c +1
-0@@ -412,6 +412,7 @@ void add_taint(unsigned int taint)extern const initcall_t __initcall_start[], __presmp_initcall_end[], __initcall_end[]; +extern const initcall_t __initcall_boot_test_start[], __initcall_boot_test_end[];void __init do_presmp_initcalls (void ) {
xen/common/kernel.c void __init do_initcalls(void) · line 433
Quoted 6 lines
xen/common/kernel.c +3
-0@@ -427,6 +428,16 @@ void __init do_initcalls(void) (*call)(); } +void __init do_init_boottests (void ) +{ +#ifdef CONFIG_BOOT_SELFTEST
I think it would be worth printing before and after to indicate the begin/end of the selftest.
Quoted 18 lines
xen/common/kernel.c +7
-0+const initcall_t *call; +for ( call = __initcall_boot_test_start; call < __initcall_boot_test_end; + call++ ) + (*call)(); +#endif +} +#ifdef CONFIG_HYPFS static unsigned int __read_mostly major_version;static unsigned int __read_mostly minor_version;xen/include/xen/init.h +0
-0@@ -66,11 +66,14 @@ typedef void (*exitcall_t)(void); static const initcall_t __initcall_##fn __init_call("presmp") = (fn)#define __initcall (fn) \ static const initcall_t __initcall_##fn __init_call("1") = (fn)
xen/include/xen/init.h typedef void (*exitcall_t)(void); · line 78
Quoted 10 lines
xen/include/xen/init.h +3
-0+#define __initcallboottest (fn) \ + static const initcall_t __initcall_##fn __init_call("boottest") = (fn)#define __exitcall (fn) \ static exitcall_t __exitcall_##fn __exit_call = fnvoid do_presmp_initcalls (void );void do_initcalls (void ); +void do_init_boottests (void );#endif /* __ASSEMBLER__ */
Cheers,
Signature · 1 line
Julien Grall
Hi again,
xen/arch/arm/gic-test.c line 3
Quoted 9 lines · Ayan Kumar Halder
xen/arch/arm/gic-test.c new file +3
-0@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/delay.h>
I think this header is also unecessary.
Quoted 4 lines
xen/arch/arm/gic-test.c new file +4
-0+#include <xen/init.h> +#include <xen/param.h> +#include <xen/shutdown.h> +#include <asm/gic.h>
[...]
Quoted 18 lines
xen/arch/arm/gic-test.c new file +18
-0+static int __init gic_self_sgi_test (void ) +{ +if ( !gic_test ) +return 0 ; + +printk ("Sending GIC_SGI_TEST to self CPU%u\n" ,smp_processor_id ()); +send_SGI_self (GIC_SGI_TEST ); + +if (smp_processor_id () ==0 ) + { +printk ("Sending GIC_SGI_DUMP_STATE to CPU0\n" ); +smp_send_state_dump (0 ); + +return 0 ; + } + +printk ("Sending GIC_SGI_TEST to CPU0 from CPU%u\n" ,smp_processor_id ()); +send_SGI_one (0 ,GIC_SGI_TEST );
xen/arch/arm/gic-test.c line 50
Quoted 10 lines
xen/arch/arm/gic-test.c new file +10
-0+ +/* Execute this test only from the last core */ +if (smp_processor_id () == (smp_get_max_cpus () -1 ) ) + { +printk ("Sending GIC_SGI_TEST to all except CPU%u\n" ,smp_processor_id ()); +send_SGI_allbutself (GIC_SGI_TEST ); + } + +return 0 ; +
Style: The newline seems spurious.
xen/arch/arm/gic-test.c
Quoted 2 lines
xen/arch/arm/gic-test.c new file +2
-0+} +__initcallboottest (gic_self_sgi_test);
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 9 lines · Ayan Kumar Halder
Quoted 5 lines
Boot self-tests (also referred to as boot-time tests or power-on self-tests) are intended to validate internal features of Xen during bring-up. They are meant to be run in a debug / validation environment; Xen is not expected to remain functional for production use after the self-tests have executed.
Looking at the code below, isn't Xen functional even after the self-test?
Yes as discussed on Matrix, I have modified the test so that Xen boots normally after running the self-test.
Xen will panic if the self test fails.
Quoted 7 lines
Quoted 7 lines
The purpose of these tests is to catch
hardware configuration issues early and to confirm that the platform on which Xen has been brought up is sane. The expected flow is:
build Xen with the self-tests enabled, boot it, inspect the results, and then reboot into the usual production configuration.
Quoted 7 lines
Quoted 5 lines
Introduce the tests to confirm that:
1. A cpu can send SGI 0 to itself
2. A cpu can send SGI 0 to another specific CPU
3. A cpu can send SGI 0 to all the other CPUs
4. A cpu can send SGI 1 to another CPUI am not sure what you meant by SGI 0 and SGI 1? Below you seem to be use only a SGI (which is neither 0 or 1) except for one specific test: cpu 0 injecting an SGI to a specific CPU (0).
Yes, I fixed this in v3.
Quoted 184 lines
Quoted 184 lines
These tests aim to test Xen has configured the GIC correctly to use SGIs. Thus, the tests invoke specific APIs of GIC driver.
Also, introduce a config
CONFIG_BOOT_SELFTESTwhich enables these tests. The option defaults to N; it should be disabled for production builds and is intended for the validation pipeline and coverage measurement. The tests run during Xen boot and validate internal interfaces such as Xen's interface with hardware, firmware and the bootloader.Also, introduce an integer command line parameter "gic-test". By default, it is set to 0 which means no tests are enabled.
For running SGI tests, "gic-test" should be set to 1. In future if we add tests for distributer, ITS, LPI, etc, then we can use different numbers. Thus, each number denotes a functionality of GICv3 which can be tested independently and within a single boot of Xen.In this way, we ensure that the tests to validate SGIs do not impact any other tests.
In order to keep all the boot-time self-tests together in the binary, we have introduced a separate section "initcallboottest". All the tests are registered using
__initcallboottest. During the bootup of each core, Xen invokesdo_init_boottests()to run the these tests. All these tests are invoked before Xen creates the domains (in case of primary core) or runs the idle loop (in case of secondary core).Note: it was suggested that, once the boot self-tests have run, Xen should call
machine_halt()rather than continue booting (since this build is only intended for validation). This is not wired in here because the SGIs are sent from the primary and secondary CPUs and received asynchronously on the target CPUs. There is no definite point in the boot flow at which Xen can know that every send has been observed by its receiver, so "after the tests have completed" has no well-defined moment at which to insertmachine_halt().Signed-off-by Ayan Kumar Halder <[email protected]>Signed-off-by Michal Orzel <[email protected]>---
Link to v1 (RFC):
https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00956.htmlUpstream CI run (xen-project/people/ayankuma/xen fork, one commit on top of xen-project/xen staging — all Linux builds + tests including qemu-smoke-boot-selftest-arm64-gcc-debug passed; only the macos jobs sit pending because the personal fork has no macos runner):
https://gitlab.com/xen-project/people/ayankuma/xen/-/pipelines/2561806695Changes in v2:
- Renamed the patch from "xen/arm: Introduce GICV3 Self Tests" to "Add GICv3 SGI boot/self tests in Xen", and rewrote the commit message to explain the intent of boot self-tests (debug / validation builds only, Xen not expected to remain functional afterwards).
- Moved the selftest code out ofgic-v3.cinto a dedicated filexen/arch/arm/gic-test.c, gated byCONFIG_BOOT_SELFTEST(Stefano, Grygorii).
- Introduced a generic boot-self-test framework: new section "initcallboottest", registration macro__initcallboottest, anddo_init_boottests()invoked once per CPU afterlocal_irq_enable(), so the test runs on every CPU (boot + secondaries) and no longer collides with the IRQ-enable timing ingicv3_init()(Julien #1, Julien #3).
- AddedKconfigoptionCONFIG_BOOT_SELFTESTin xen/arch/arm/Kconfig (arm-only for now; arch-specific because the only registered test is GICv3-specific).
- Reserved a dedicated SGI valueGIC_SGI_TESTin enumgic_sgi(xen/arch/arm/include/asm/gic.h), so the selftest never reuses a functional SGI (Grygorii #3).
- Added a runtime integer command-line parameter "gic-test" so the selftest binary can be shipped but its execution selected at boot (gic-test=0 -> no-op; gic-test=1 -> SGI tests). Future GICv3 features (distributor, ITS, LPI, ...) can claim further values (Grygorii #2, partial).
- Documented whymachine_halt()is not invoked after the tests:
SGI delivery is asynchronous, so there is no well-defined point after which every send has been observed by its receiver (Julien #2).
- Wired the tests into upstream GitLab CI: new build job alpine-3.18-gcc-debug-arm64-boot-selftest, new test job qemu-smoke-boot-selftest-arm64-gcc-debug, and the runner scriptautomation/scripts/qemu-boot-selftest-arm64.shthat dumps the QEMU virt DTB, injects
"gic-test=1 console=dtuartsync_console" into /chosen/xen,xen-bootargs via fdtput, boots Xen, and checks for each "SendingGIC_SGI_TEST..." followed by the matching "CPU%u:GIC_SGI_TESTreceived".automation/gitlab-ci/build.yaml | 8 ++ automation/gitlab-ci/test.yaml | 8 ++ .../scripts/qemu-boot-selftest-arm64.sh | 81 +++++++++++++++++++ xen/arch/arm/Kconfig | 15 ++++ xen/arch/arm/Makefile | 1 + xen/arch/arm/gic-test.c | 52 ++++++++++++ xen/arch/arm/gic.c | 5 ++ xen/arch/arm/include/asm/gic.h | 3 + xen/arch/arm/setup.c | 2 + xen/arch/arm/smpboot.c | 2 + xen/arch/arm/xen.lds.S | 4 + xen/common/kernel.c | 11 +++ xen/include/xen/init.h | 3 +
13 files changed, 195 insertions(+)create mode 100755
automation/scripts/qemu-boot-selftest-arm64.shcreate mode 100644xen/arch/arm/gic-test.cautomation/gitlab-ci/build.yaml +0
-0@@ -439,6 +439,14 @@ alpine-3.18-gcc-debug-arm64:
CONFIG_UBSAN=y
CONFIG_UBSAN_FATAL=y
+alpine-3.18-gcc-debug-arm64-boot-selftest:
+ extends: .gcc-arm64-build-debug
+ <<: *build-test
+ variables:
+ CONTAINER: alpine:3.18-arm64v8
+EXTRA_XEN_CONFIG: |
+CONFIG_BOOT_SELFTEST=y
+
alpine-3.18-gcc-arm64-randconfig:
extends: .gcc-arm64-build
variables:automation/gitlab-ci/test.yaml +0
-0@@ -524,6 +524,14 @@ qemu-smoke-dom0less-arm64-gcc-debug-gicv3:- *arm64-test-needs
- alpine-3.18-gcc-debug-arm64 +qemu-smoke-boot-selftest-arm64-gcc-debug:
+ extends: .qemu-arm64
+ script:
+ -./automation/scripts/qemu-boot-selftest-arm64.sh2>&1 | tee ${LOGFILE}
+ needs:
+ - *arm64-test-needs
+ - alpine-3.18-gcc-debug-arm64-boot-selftest
+
qemu-smoke-dom0less-arm64-gcc-debug-staticmem:
extends: .qemu-arm64
script:automation/scripts/qemu-boot-selftest-arm64.sh new file +5
-0@@ -0,0 +1,81 @@ +#!/bin/bash + +set -ex -o pipefail + +# Boot the prebuilt Xen binary under QEMU with
CONFIG_BOOT_SELFTEST=yenabled
+# and gic-test=1 in xen,xen-bootargs, then verify the four GICv3 SGI self-testsautomation/scripts/qemu-boot-selftest-arm64.sh new file +14
-0+# pass by inspecting the serial log. + +XEN=binaries/xen +QEMU=./binaries/qemu-system-aarch64 +DTB_RAW=binaries/virt.dtb +DTB=binaries/virt-bootselftest.dtb +LOG=smoke.serial + +test -x ${QEMU} +test -f ${XEN} + +# Dump the auto-generated DT from the QEMU virt machine, then inject +# /chosen/xen,xen-bootargs. The selftest infrastructure invokes +# do_init_boottests() during early boot; gic-test=1 selects theGICv3 SGI
automation/scripts/qemu-boot-selftest-arm64.sh new file +5
-0+# tests. +# -net none avoids QEMU's default virtio-net-pci, whose efi-virtio.rom +# is not shipped with the qemu-system-aarch64 artifact used in CI. +${QEMU} \ + -machinevirt,virtualization=true,gic-version=3,dumpdtb=${DTB_RAW} \
+ -cpu cortex-a57 -m 1024 -smp 2 -display none -net noneautomation/scripts/qemu-boot-selftest-arm64.sh new file +3
-0+ +cp ${DTB_RAW} ${DTB} +fdtput -t s ${DTB} /chosen xen,xen-bootargs \
Quoted 8 lines
automation/scripts/qemu-boot-selftest-arm64.sh line 35
Quoted 6 lines
+ "gic-test=1 console=dtuart
sync_console"automation/scripts/qemu-boot-selftest-arm64.sh new file +5
-0+ +rm -f ${LOG} +timeout 60 ${QEMU} \ + -machine virt,virtualization=true,gic-version=3 \ + -cpu cortex-a57 -m 1024 -smp 2 \This means that there is no much difference between "send an SGI to a specific CPU" and "send an SGI to others CPU". I think it would be more meaningful to use 3 or more pCPUs.
Yes, now I use 4 pCPUs.
Quoted 57 lines
Quoted 57 lines
+ -serial file:${LOG} \
+ -monitor none -display none -no-reboot -net none \
+ -dtb ${DTB} \
+ -kernel ${XEN} || trueautomation/scripts/qemu-boot-selftest-arm64.sh new file +25
-1+ +# Each "Sending GIC_SGI_TEST ..." line must be followed by the matching +# "CPU%u: GIC_SGI_TEST received". +fail=0 +check_pair() { + local send_pat=$1 + local recv_pat=$2 + local send_line recv_line + + send_line=$(grep -n -- "${send_pat}" ${LOG} | head -n1 | cut -d: -f1) + if [ -z "${send_line}" ]; then + echo "MISSING: ${send_pat}" + fail=1 + return + fi + + recv_line=$(grep -n -- "${recv_pat}" ${LOG} \ + | awk -v bl="${send_line}" -F: '$1 > bl {print $1; exit}') + if [ -z "${recv_line}" ]; then + echo "MISSING (after line ${send_line}): ${recv_pat}" + fail=1 + return + fi + + echo "OK: '${send_pat}' -> '${recv_pat}' (lines ${send_line} ->${recv_line})"
automation/scripts/qemu-boot-selftest-arm64.sh new file +4
-0+} + +# Boot CPU sends SGI to itself +check_pair "Sending GIC_SGI_TEST to self CPU0" "CPU0: GIC_SGI_TESTreceived"
automation/scripts/qemu-boot-selftest-arm64.sh new file +2
-0+# Secondary CPU sends SGI to itself +check_pair "Sending GIC_SGI_TEST to self CPU1" "CPU1: GIC_SGI_TESTreceived"
automation/scripts/qemu-boot-selftest-arm64.sh new file +2
-0+# Secondary CPU sends SGI to primary +check_pair "Sending GIC_SGI_TEST to CPU0 from CPU1" "CPU0:
GIC_SGI_TESTreceived"automation/scripts/qemu-boot-selftest-arm64.sh new file +2
-0+# Send to all-but-self +check_pair "Sending GIC_SGI_TEST to all except CPU1" "CPU0:
GIC_SGI_TESTreceived"automation/scripts/qemu-boot-selftest-arm64.sh new file +7
-0+ +if [ ${fail} -ne 0 ]; then + echo "FAILED" + exit 1 +fi + +echo "PASSED"xen/arch/arm/Kconfig +0
-0
Quoted 8 lines
Quoted 6 lines
xen/arch/arm/Kconfig +0
-0@@ -476,6 +476,21 @@ config ARM64_HARDEN_BRANCH_PREDICTORconfig
ARM32_HARDEN_BRANCH_PREDICTORdef_booly ifARM_32&&HARDEN_BRANCH_PREDICTOR+configBOOT_SELFTEST
+ bool "Enable boot-time self-tests"
+ default nAbove you said, this is not meant for production. So I was expecting to see a dependency on
CONFIG_DEBUG.
yes, I have added this
Quoted 2 lines
If the intention is to use it in release build, given the current behavior (e.g. breaking test), I think this should depend on UNSUPPORTED so we don't get security report because Xen is broken after the boot tests.
No, it is disabled in release build.
Quoted 14 lines
Quoted 2 lines
+ help> + This option enables boot-time self-tests that
validate Xen's internal
Quoted 10 lines
+ interfaces with hardware, firmware and the bootloader. The tests are
+ registered with__initcallboottestand executed bydo_init_boottests()
+ during early boot, before domains are created.
+
+ These tests are intended for validation and coverage measurement, not
+ for production builds. With this option enabled, Xen may not be + functional after the tests have run.
Quoted 3 lines
If we know a test break, I think it is best that Xen doesn't continue. Otherwise, it is quite confusing for the user to know what's going on.
My preference is the bootest would act like other self tests and Xen can continue booting normally. So the tests could also be meaningful in non-test setups.
Yes, now Xen is functional even after running the self tests.
Quoted 24 lines
Quoted 24 lines
xen/arch/arm/Kconfig +3
-0+ + If unsure, say N. +source "
arch/arm/platforms/Kconfig"
source "common/Kconfig"xen/arch/arm/Makefile +0
-0@@ -24,6 +24,7 @@ obj-y += domctl.oobj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-y += efi/
obj-y += gic.o
+obj-$(CONFIG_BOOT_SELFTEST) += gic-test.init.o
obj-$(CONFIG_GICV2) += gic-v2.o
obj-$(CONFIG_GICV3) += gic-v3.o
obj-$(CONFIG_HAS_ITS) += gic-v3-its.oxen/arch/arm/gic-test.c new file +0
-0@@ -0,0 +1,52 @@
Quoted 8 lines
xen/arch/arm/gic-test.c line 6
Quoted 6 lines
xen/arch/arm/gic-test.c new file +6
-0+/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/delay.h> +#include <xen/init.h> +#include <xen/param.h> +#include <xen/shutdown.h> Can you clarify why you need this header?
I have dropped this.
Quoted 12 lines
xen/arch/arm/gic-test.c line 15
Quoted 10 lines
xen/arch/arm/gic-test.c new file +9
-0+#include <asm/gic.h> + +/* +* gic_test: Specifies the gic test to be executed. +* 0 = no tests are executed +* 1 = SGI tests are executed +*/ +static unsigned int __initdata gic_test =0 ; +integer_param ("gic-test" , gic_test);Given this is mean to be 0 or 1, why not using "
boolean_param"?
Yes, I have this as a boolean param
Quoted 2 lines
Also, new command line option should be documented in the docs. That said, I am not really sure about
I have documented it.
Quoted 14 lines
Quoted 14 lines
xen/arch/arm/gic-test.c new file +13
-0+ +/* +* CPU0: GIC_SGI_DUMP_STATE to self +* CPU{0-N}: GIC_SGI_TEST to self +* CPU{1-N}: GIC_SGI_TEST to CPU0 +* CPU{N}: GIC_SGI_TEST to all but self +*/ +static int __init gic_self_sgi_test (void ) +{ + if ( !gic_test ) + return 0; + + printk("Sending GIC_SGI_TEST to self CPU%u\n", smp_processor_id());
Quoted 8 lines
xen/arch/arm/gic-test.c line 34
Quoted 6 lines
xen/arch/arm/gic-test.c new file +6
-0+ send_SGI_self(GIC_SGI_TEST); + + if ( smp_processor_id() == 0 ) + { + printk("Sending GIC_SGI_DUMP_STATE to CPU0\n"); + smp_send_state_dump(0);OOI, why is this only called for CPU0? You also don't seem to check that
smp_send_state_dump()in the CI test.
Ah, I have dropped it.
Quoted 4 lines
Quoted 4 lines
xen/arch/arm/gic-test.c new file +4
-0+ + return 0; + } +
Quoted 8 lines
Quoted 6 lines
xen/arch/arm/gic-test.c new file +1
-0+ printk("Sending GIC_SGI_TEST to CPU0 from CPU%u\n",
smp_processor_id());
+send_SGI_one(0, GIC_SGI_TEST);
+
+ /* Execute this test only from the last core */ + if (smp_processor_id()== (smp_get_max_cpus()- 1) )This is relying on how Xen is boot CPUs. Would it be better to check the number of online CPUs at the time of the check? (You might need to re-order some code for that)
yes, I have changed the code. I now check the number of online CPUs.
Quoted 17 lines
Quoted 17 lines
+ {
+printk("Sending GIC_SGI_TEST to all except CPU%u\n", smp_processor_id());
+send_SGI_allbutself(GIC_SGI_TEST);
+ }xen/arch/arm/gic-test.c new file +5
-0+ + return 0; + +} +__initcallboottest (gic_self_sgi_test);xen/arch/arm/gic.c +0
-0@@ -324,6 +324,11 @@ static void do_static_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi)
Quoted 8 lines
Quoted 6 lines
case
GIC_SGI_CALL_FUNCTION:
smp_call_function_interrupt();
break;
+#ifdefCONFIG_BOOT_SELFTEST
+ caseGIC_SGI_TEST:
+printk("CPU%u: GIC_SGI_TEST received\n", smp_processor_id());To confirm, we will solely rely on logging? IOW, there is no plan to have Xen self-sufficient (e.g. using a global variable).
yes, I know use a per cpu variable.
Quoted 68 lines
Quoted 68 lines
+ break;
+#endif
default:
panic("Unhandled SGI %d on CPU%d\n", sgi, smp_processor_id()); break;xen/arch/arm/include/asm/gic.h +3
-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, };diff --git
a/xen/arch/arm/setup.cb/xen/arch/arm/setup.cindex6310a47d68..4e5db93027100644xen/arch/arm/setup.c +1
-0@@ -470,6 +470,8 @@ void asmlinkage __init noreturnstart_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 +1
-0@@ -405,6 +405,8 @@ void asmlinkage noreturn start_secondary(void) printk(XENLOG_DEBUG "CPU %u booted.\n", smp_processor_id()); + do_init_boottests(); + startup_cpu_idle_loop(); }diff --git
a/xen/arch/arm/xen.lds.Sb/xen/arch/arm/xen.lds.Sindex2d5f1c516d..14f64a856c100644xen/arch/arm/xen.lds.S +3
-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)xen/common/kernel.c +1
-0@@ -412,6 +412,7 @@ void add_taint(unsigned int taint) extern const initcall_t __initcall_start[], __presmp_initcall_end[], __initcall_end[]; +extern const initcall_t __initcall_boot_test_start[], __initcall_boot_test_end[]; void __init do_presmp_initcalls(void) {
Quoted 8 lines
xen/common/kernel.c void __init do_initcalls(void) · line 432
Quoted 6 lines
xen/common/kernel.c +2
-0@@ -427,6 +428,16 @@ void __init do_initcalls(void) (*call)(); } +void __init do_init_boottests(void) +{ +#ifdef CONFIG_BOOT_SELFTEST I think it would be worth printing before and after to indicate the begin/end of the selftest.
yes, I have added the prints in v3.
Quoted 23 lines
Quoted 23 lines
xen/common/kernel.c +7
-0+ const initcall_t *call; + for ( call = __initcall_boot_test_start; call < __initcall_boot_test_end; + call++ ) + (*call)(); +#endif +} + #ifdef CONFIG_HYPFS static unsigned int __read_mostly major_version;static unsigned int
__read_mostlyminor_version;xen/include/xen/init.h +2
-0@@ -66,11 +66,14 @@ typedef void (*exitcall_t)(void); static const initcall_t __initcall_##fn __init_call("presmp") = (fn) #define __initcall(fn) \ static const initcall_t __initcall_##fn __init_call("1") = (fn) +#define __initcallboottest (fn) \ + static const initcall_t __initcall_##fn __init_call("boottest") = (fn)
Quoted 8 lines
Quoted 6 lines
xen/include/xen/init.h +0
-0#define __exitcall(fn) \static
exitcall_t__exitcall_##fn__exit_call= fn voiddo_presmp_initcalls(void);
voiddo_initcalls(void);
+voiddo_init_boottests(void);
#endif /*__ASSEMBLER__*/Cheers,
Thanks
- Ayan
Quoted 2 lines
PATCH v3 1/1 Add GIC SGI boot/self tests in Xen
In reply to Ayan Kumar HalderBoot 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.
---
Upstream CI run:
https://gitlab.com/xen-project/people/ayankuma/xen/-/pipelines/2799278627
Changes in v3:
- Rewrote the commit message: dropped the claim that Xen is not functional after the tests (it is), and the misleading "SGI 0 / SGI 1" numbering - only one SGI, GIC_SGI_TEST, is used (Julien).
- Retitled from "GICv3 SGI" to "GIC SGI": the tests only use send_SGI_{self,one,allbutself}(), which GICv2 implements too. Verified by running them on arm32/GICv2.
- The tests are now self-checking instead of log-scraping: each CPU counts the GIC_SGI_TEST interrupts it takes and the sender waits for that count, panicking after 100ms. Xen no longer continues on a platform where SGI delivery is broken, and is otherwise unaffected, so the option is meaningful on an ordinary debug build (Julien).
- CONFIG_BOOT_SELFTEST now depends on DEBUG (Julien).
- "gic-test" is a boolean_param() and is documented in docs/misc/xen-command-line.pandoc (Julien).
- Dropped the unnecessary <xen/delay.h> and <xen/shutdown.h> includes, and the unchecked smp_send_state_dump() call (Julien).
- The "all but self" test is run by whichever CPU observes it is the last to arrive, comparing against num_online_cpus(), and targets cpu_online_map minus itself, rather than keying off smp_get_max_cpus() - 1 (Julien).
- do_init_boottests() prints a begin/end marker (Julien).
- Removed the spurious blank line before the closing brace (Julien).
- The CI test now boots 4 CPUs, so that "send to CPU0" and "send to all but self" cover different sets of CPUs (Julien).
- The registration macro and do_init_boottests() moved to arch/arm, so that xen/include/xen/init.h and xen/common/kernel.c are untouched: the .initcallboottest.init section only exists in arch/arm/xen.lds.S, and a test registered elsewhere would land in an orphan section.
- do_init_boottests() is no longer __init: it is called from start_secondary(), which lives in .text.
- The static counter used to spot the last CPU is __initdata, so it no longer occupies .bss for the life of the hypervisor.
- Kconfig: use tabs to match the rest of arch/arm/Kconfig, and drop the redundant "default n".
- gic-test.c is SPDX GPL-2.0-or-later, to match the neighbouring GIC files.
- The CI test script takes qemu-system-aarch64 from the test container's PATH, the same way the other qemu-smoke-*-arm64 scripts do, rather than expecting it in binaries/.
- Rebased onto current staging: the CI jobs are named after alpine 3.24 rather than 3.18.
Changes in v2:
- Renamed the patch from "xen/arm: Introduce GICV3 Self Tests" to "Add GICv3 SGI boot/self tests in Xen", and rewrote the commit message to explain the intent of boot self-tests (debug / validation builds only, Xen not expected to remain functional afterwards).
- Moved the selftest code out of gic-v3.c into a dedicated file xen/arch/arm/gic-test.c, gated by CONFIG_BOOT_SELFTEST (Stefano, Grygorii).
- Introduced a generic boot-self-test framework: new section "initcallboottest", registration macro __initcallboottest, and do_init_boottests() invoked once per CPU after local_irq_enable(), so the test runs on every CPU (boot + secondaries) and no longer collides with the IRQ-enable timing in gicv3_init() (Julien #1, Julien #3).
- Added Kconfig option CONFIG_BOOT_SELFTEST in xen/arch/arm/Kconfig (arm-only for now; arch-specific because the only registered test is GICv3-specific).
- Reserved a dedicated SGI value GIC_SGI_TEST in enum gic_sgi (xen/arch/arm/include/asm/gic.h), so the selftest never reuses a functional SGI (Grygorii #3).
- Added a runtime integer command-line parameter "gic-test" so the selftest binary can be shipped but its execution selected at boot (gic-test=0 -> no-op; gic-test=1 -> SGI tests). Future GICv3 features (distributor, ITS, LPI, ...) can claim further values (Grygorii #2, partial).
- Documented why machine_halt() is not invoked after the tests:
SGI delivery is asynchronous, so there is no well-defined point after which every send has been observed by its receiver (Julien #2).
- Wired the tests into upstream GitLab CI: new build job alpine-3.18-gcc-debug-arm64-boot-selftest, new test job qemu-smoke-boot-selftest-arm64-gcc-debug, and the runner script automation/scripts/qemu-boot-selftest-arm64.sh that dumps the QEMU virt DTB, injects
"gic-test=1 console=dtuart sync_console" into /chosen/xen,xen-bootargs via fdtput, boots Xen, and checks for each "Sending GIC_SGI_TEST ..." followed by the matching "CPU%u: GIC_SGI_TEST received".
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
@@ -1267,6 +1267,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 (see arch/arm/gic-test.c). */ +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
@@ -50,6 +50,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
@@ -83,6 +83,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" ,
@@ -470,6 +488,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
@@ -28,6 +28,7 @@#include <asm/gic.h> #include <asm/procinfo.h> #include <asm/psci.h> +#include <asm/setup.h> #include <asm/acpi.h> #include <asm/tee/tee.h>
@@ -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
Re: [PATCH v3 for 4.23] Add GIC SGI boot/self tests in Xen
Hi Ayan,
It is usually preferred to send a new version in its own thread rather than in-reply-to an existing version.
Quoted 18 lines · Ayan Kumar Halder
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.oxen/arch/arm/gic-test.c new file +0
-0
xen/arch/arm/gic-test.c line 1
Quoted 1 line
xen/arch/arm/gic-test.c new file +1
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */
The preferred license for Xen is GPLv2-only (see COPYING). Can you confirm the use of GPL2+ is intended?
Quoted 11 lines
xen/arch/arm/gic-test.c new file +11
-0+ +#include <xen/atomic.h> +#include <xen/cpumask.h> +#include <xen/init.h> +#include <xen/lib.h> +#include <xen/param.h> +#include <xen/percpu.h> +#include <xen/smp.h> +#include <xen/time.h> +#include <asm/gic.h> +#include <asm/processor.h>
xen/arch/arm/gic-test.c line 22
Quoted 10 lines
xen/arch/arm/gic-test.c new file +10
-0+#include <asm/setup.h> + +static bool __initdata opt_gic_test; +boolean_param ("gic-test" , opt_gic_test); + +static DEFINE_PER_CPU(unsigned int, sgi_test_count); + +void gic_sgi_test_interrupt (void ) +{ +this_cpu (sgi_test_count)++;
In sgi_count(), you are using ACCESS_ONCE() to read the content of the variable, but I am not entirely sure this_cpu(...)++ is guarantee to be a single write.
As this happen on different CPU, don't we also need to use ACCESS_ONCE() here too or atomically increment?
[...]
Quoted 31 lines
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 +3
-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, };
xen/arch/arm/include/asm/gic.h extern void send_SGI_one(unsigned int cpu, enum gic_sgi sgi); · line 328
Quoted 5 lines
xen/arch/arm/include/asm/gic.h +2
-0@@ -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 (see arch/arm/gic-test.c). */
I would suggest to remove (see ...). One can easily find gic_sgi_test_interrupt() and this reduces the risk of stale file name.
Quoted 69 lines
xen/arch/arm/include/asm/gic.h +3
-0+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@@ -50,6 +50,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@@ -83,6 +83,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" ,@@ -470,6 +488,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 +0
-0
xen/arch/arm/smpboot.c line 31
Quoted 4 lines
xen/arch/arm/smpboot.c +1
-0@@ -28,6 +28,7 @@#include <asm/gic.h> #include <asm/procinfo.h> #include <asm/psci.h> +#include <asm/setup.h>
Style: I think this wants to go after asm/tee/tee.h (acpi.h seems to be misplaced).
Quoted 17 lines
xen/arch/arm/smpboot.c +2
-0#include <asm/acpi.h> #include <asm/tee/tee.h> @@ -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 +0
-0
xen/arch/arm/xen.lds.S SECTIONS · line 155
Quoted 10 lines
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)
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v3 for 4.23] Add GIC SGI boot/self tests in Xen
Quoted 1 line · Julien Grall
Hi Ayan,
Hi Julien,
Quoted 2 lines
It is usually preferred to send a new version in its own thread rather than in-reply-to an existing version.
Apologies, this was my mistake (bad git send command).
Quoted 15 lines · Ayan Kumar Halder
Quoted 13 lines
xen/arch/arm/Makefile +0
-0@@ -24,6 +24,7 @@ obj-y += domctl.oobj-$(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.oxen/arch/arm/gic-test.c +0
-0
Quoted 8 lines
xen/arch/arm/gic-test.c line 1
Quoted 6 lines
new file mode 100644
index 0000000000..9ddd47cad2xen/arch/arm/gic-test.c new file +1
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ The preferred license for Xen is GPLv2-only (see COPYING). Can you confirm the use of GPL2+ is intended?
fixed
Quoted 25 lines
Quoted 12 lines
xen/arch/arm/gic-test.c new file +11
-0+ +#include <xen/atomic.h> +#include <xen/cpumask.h> +#include <xen/init.h> +#include <xen/lib.h> +#include <xen/param.h> +#include <xen/percpu.h> +#include <xen/smp.h> +#include <xen/time.h> +#include <asm/gic.h> +#include <asm/processor.h> xen/arch/arm/gic-test.c line 22
Quoted 10 lines
xen/arch/arm/gic-test.c new file +10
-0+#include <asm/setup.h> + +static bool __initdata opt_gic_test; +boolean_param ("gic-test" , opt_gic_test); + +static DEFINE_PER_CPU(unsigned int, sgi_test_count); + +void gic_sgi_test_interrupt (void ) +{ + this_cpu(sgi_test_count)++;In
sgi_count(), you are usingACCESS_ONCE()to read the content of the variable, but I am not entirely sure this_cpu(...)++ is guarantee to be a single write.
Quoted 1 line
As this happen on different CPU, don't we also need to use
ACCESS_ONCE()here too
ACCESS_ONCE(this_cpu(sgi_test_count))++;
Quoted 109 lines
or atomically increment?
[...]
Quoted 31 lines
xen/arch/arm/gic.c +0
-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;xen/arch/arm/gic.c +5
-0+#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 +3
-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);Quoted 5 lines
extern void
send_SGI_self(enum gic_sgi sgi); extern voidsend_SGI_allbutself(enum gic_sgi sgi); +#ifdefCONFIG_BOOT_SELFTEST
+/* Record aGIC_SGI_TESTdelivered to this CPU (seearch/arm/gic-test.c). */I would suggest to remove (see ...). One can easily find
gic_sgi_test_interrupt()and this reduces the risk of stale file name.Quoted 66 lines
xen/arch/arm/include/asm/gic.h +3
-0+void gic_sgi_test_interrupt (void ); +#endif +/* print useful debug info */
extern voidgic_dump_info(struct vcpu *v);
extern voidgic_dump_vgic_info(struct vcpu *v);xen/arch/arm/include/asm/setup.h +0
-0@@ -50,6 +50,15 @@ void setup_mm(void); extern uint32_t hyp_traps_vector[]; void init_traps(void);+#ifdef
CONFIG_BOOT_SELFTEST
+#define__initcallboottest(fn)\
+ static constinitcall_t__initcall_##fn__init_call("boottest")= (fn)xen/arch/arm/include/asm/setup.h +6
-0+ +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_tp2mt, struct rangeset*iomem_ranges, struct rangeset*irq_ranges); diff --gita/xen/arch/arm/setup.cb/xen/arch/arm/setup.c
index6310a47d68..c7abbdb04e100644xen/arch/arm/setup.c +0
-0@@ -83,6 +83,24 @@ static void __init init_idle_domain(void) /* TODO: setup_idle_pagetable(); */ }+#ifdef
CONFIG_BOOT_SELFTESTxen/arch/arm/setup.c +10
-0+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)();xen/arch/arm/setup.c +5
-0+ + printk("CPU%u: boot self-tests done\n", smp_processor_id()); +} +#endif /* CONFIG_BOOT_SELFTEST */ +static const char *
__initdataprocessor_implementers[] = { ['A'] = "ARM Limited",
['B'] = "Broadcom Corporation",xen/arch/arm/setup.c +1
-0@@ -470,6 +488,8 @@ void asmlinkage __init noreturnstart_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 +0
-1--- a/xen/arch/arm/smpboot.c
Quoted 8 lines
xen/arch/arm/smpboot.c line 31
Quoted 6 lines
+++
b/xen/arch/arm/smpboot.cxen/arch/arm/smpboot.c +1
-0@@ -28,6 +28,7 @@ #include <asm/gic.h> #include <asm/procinfo.h> #include <asm/psci.h> +#include <asm/setup.h> Style: I think this wants to go after
asm/tee/tee.h(acpi.hseems to be misplaced).
fixed.
- Ayan