Hi Ayan,

On 12/09/2025 18:00, Ayan Kumar Halder wrote:
Introduce CONFIG_GICV3_SELFTEST to enclose tests for GICv3 driver.
Test that Xen is able to generate SGIs.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.hal...@amd.com>
---
One of the aim of functional safety is to test hw/sw interface. This means that
Xen is able to configure the hardware correctly for the desired functionalities.

Normally this is tested from the VMs. For eg if a VM is able to receive irq, 
this
implies that Xen has configured the GICv3 interface 'correctly'. However this is
a high level (or integration) test which uses not only the GICv3 interface
between Xen and VM, but the interrupt injection code for Xen to VMs.

We want to have some kind of unit tests to check that Xen is able to receive
various interrupts, set priorities, etc. Here, we have written unit tests for
software generated interrupts (SGIs) as example.

These tests are expected to be triggered as Xen boots (right after Xen has
initialised the GICv3 interface ie gicv3_init(). The aim of this test is to
check whether Xen can trigger SGIs after gicv3_init() is invoked. If so, we can
claim that gicv3_init() was done properly to be able to trigger SGIs.

To clarify, this only guarantees that the boot CPU can send SGIs to self. Secondary CPUs are brought up later and will need their own setup to enable SGIs.

Likewise
we will have tests to check for priorities, SPIs, etc.

A script will parse the logs and claim that Xen is able to trigger SGIs.

  xen/arch/arm/Kconfig  |  8 ++++++++
  xen/arch/arm/gic-v3.c |  7 +++++++
  xen/arch/arm/gic.c    | 21 +++++++++++++++++++++
  3 files changed, 36 insertions(+)

diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index 950e4452c1..739f99eaa9 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -73,6 +73,14 @@ config GICV3
          Driver for the ARM Generic Interrupt Controller v3.
          If unsure, use the default setting.
+config GICV3_SELFTEST
+    bool "GICv3 driver self test"
+    default n
+    depends on GICV3
+    ---help---
+
+      Self tests to validate GICV3 driver.
+
  config HAS_ITS
          bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED
          depends on GICV3 && !NEW_VGIC && !ARM_32
diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c
index 4e6c98bada..eb0c05231c 100644
--- a/xen/arch/arm/gic-v3.c
+++ b/xen/arch/arm/gic-v3.c
@@ -1818,6 +1818,13 @@ static int __init gicv3_init(void)
gicv3_hyp_init(); +#ifdef CONFIG_GICV3_SELFTEST
+    send_SGI_self(GIC_SGI_EVENT_CHECK);
+    send_SGI_self(GIC_SGI_DUMP_STATE);
+    send_SGI_self(GIC_SGI_CALL_FUNCTION);
+    send_SGI_self(GIC_SGI_MAX);
+#endif

Looking a the code below, it seems like Xen will not be functional after running the selftests? Is this intended? If so, we need to stop Xen as soon as possible.

Also, looking at start_xen(), we call local_irq_enable() a little after gicv3_init() is called. So I am a little bit surprised this is working?

Cheers,

--
Julien Grall


Reply via email to