Implement all "panic-related" functions in a dedicated file, provide __assert_fail() and adapt includes.
Signed-off-by: Andrea Bastoni <[email protected]> --- hypervisor/Makefile | 2 +- hypervisor/arch/arm-common/control.c | 1 + hypervisor/arch/arm/control.c | 1 + hypervisor/arch/arm/traps.c | 1 + hypervisor/arch/arm64/control.c | 1 + hypervisor/arch/arm64/traps.c | 1 + hypervisor/arch/x86/amd_iommu.c | 1 + hypervisor/arch/x86/control.c | 1 + hypervisor/arch/x86/efifb.c | 1 + hypervisor/arch/x86/ioapic.c | 1 + hypervisor/arch/x86/svm.c | 1 + hypervisor/arch/x86/vmx.c | 1 + hypervisor/control.c | 55 ---------------- hypervisor/include/jailhouse/control.h | 25 -------- hypervisor/include/jailhouse/panic.h | 40 ++++++++++++ hypervisor/include/jailhouse/printk.h | 4 ++ hypervisor/panic.c | 86 ++++++++++++++++++++++++++ hypervisor/pci.c | 1 + hypervisor/printk.c | 1 + hypervisor/uart.c | 1 + 20 files changed, 145 insertions(+), 81 deletions(-) create mode 100644 hypervisor/include/jailhouse/panic.h create mode 100644 hypervisor/panic.c diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 3807e608..c4965014 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -42,7 +42,7 @@ KBUILD_CFLAGS += -include $(INC_CONFIG_H) endif CORE_OBJECTS = setup.o printk.o paging.o control.o lib.o mmio.o pci.o ivshmem.o -CORE_OBJECTS += uart.o uart-8250.o +CORE_OBJECTS += uart.o uart-8250.o panic.o ifdef CONFIG_JAILHOUSE_GCOV CORE_OBJECTS += gcov.o diff --git a/hypervisor/arch/arm-common/control.c b/hypervisor/arch/arm-common/control.c index ea6d6534..9df76549 100644 --- a/hypervisor/arch/arm-common/control.c +++ b/hypervisor/arch/arm-common/control.c @@ -14,6 +14,7 @@ #include <jailhouse/control.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <asm/control.h> #include <asm/psci.h> #include <asm/iommu.h> diff --git a/hypervisor/arch/arm/control.c b/hypervisor/arch/arm/control.c index 0e7a1b54..2c16b374 100644 --- a/hypervisor/arch/arm/control.c +++ b/hypervisor/arch/arm/control.c @@ -14,6 +14,7 @@ #include <jailhouse/control.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <jailhouse/string.h> #include <asm/control.h> #include <asm/irqchip.h> diff --git a/hypervisor/arch/arm/traps.c b/hypervisor/arch/arm/traps.c index 6b402f74..d49c4d0f 100644 --- a/hypervisor/arch/arm/traps.c +++ b/hypervisor/arch/arm/traps.c @@ -16,6 +16,7 @@ #include <jailhouse/control.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <asm/control.h> #include <asm/gic.h> #include <asm/psci.h> diff --git a/hypervisor/arch/arm64/control.c b/hypervisor/arch/arm64/control.c index 3cb5c3f8..f1e8a636 100644 --- a/hypervisor/arch/arm64/control.c +++ b/hypervisor/arch/arm64/control.c @@ -12,6 +12,7 @@ #include <jailhouse/control.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <jailhouse/string.h> #include <asm/control.h> #include <asm/irqchip.h> diff --git a/hypervisor/arch/arm64/traps.c b/hypervisor/arch/arm64/traps.c index a9086c79..d22375d6 100644 --- a/hypervisor/arch/arm64/traps.c +++ b/hypervisor/arch/arm64/traps.c @@ -13,6 +13,7 @@ #include <jailhouse/control.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <asm/control.h> #include <asm/entry.h> #include <asm/gic.h> diff --git a/hypervisor/arch/x86/amd_iommu.c b/hypervisor/arch/x86/amd_iommu.c index 40ec4e20..eb8ef248 100644 --- a/hypervisor/arch/x86/amd_iommu.c +++ b/hypervisor/arch/x86/amd_iommu.c @@ -21,6 +21,7 @@ #include <jailhouse/mmio.h> #include <jailhouse/pci.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <jailhouse/string.h> #include <jailhouse/unit.h> #include <asm/amd_iommu.h> diff --git a/hypervisor/arch/x86/control.c b/hypervisor/arch/x86/control.c index 2bc47a6a..056c3f62 100644 --- a/hypervisor/arch/x86/control.c +++ b/hypervisor/arch/x86/control.c @@ -12,6 +12,7 @@ #include <jailhouse/control.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <jailhouse/processor.h> #include <asm/apic.h> #include <asm/cat.h> diff --git a/hypervisor/arch/x86/efifb.c b/hypervisor/arch/x86/efifb.c index 372cf790..5f56f0cc 100644 --- a/hypervisor/arch/x86/efifb.c +++ b/hypervisor/arch/x86/efifb.c @@ -13,6 +13,7 @@ #include <jailhouse/control.h> #include <jailhouse/processor.h> #include <jailhouse/string.h> +#include <jailhouse/panic.h> #include <asm/efifb.h> #define EFIFB_MAX_WIDTH 1920 diff --git a/hypervisor/arch/x86/ioapic.c b/hypervisor/arch/x86/ioapic.c index 65ac00f2..25321c8a 100644 --- a/hypervisor/arch/x86/ioapic.c +++ b/hypervisor/arch/x86/ioapic.c @@ -13,6 +13,7 @@ #include <jailhouse/control.h> #include <jailhouse/mmio.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <jailhouse/string.h> #include <jailhouse/unit.h> #include <asm/apic.h> diff --git a/hypervisor/arch/x86/svm.c b/hypervisor/arch/x86/svm.c index 9b1664a5..35132a5e 100644 --- a/hypervisor/arch/x86/svm.c +++ b/hypervisor/arch/x86/svm.c @@ -20,6 +20,7 @@ #include <jailhouse/control.h> #include <jailhouse/paging.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <jailhouse/processor.h> #include <jailhouse/string.h> #include <jailhouse/utils.h> diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c index bf25d00d..f679bcb1 100644 --- a/hypervisor/arch/x86/vmx.c +++ b/hypervisor/arch/x86/vmx.c @@ -16,6 +16,7 @@ #include <jailhouse/paging.h> #include <jailhouse/processor.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <jailhouse/string.h> #include <jailhouse/control.h> #include <jailhouse/hypercall.h> diff --git a/hypervisor/control.c b/hypervisor/control.c index b99d4380..d6ede805 100644 --- a/hypervisor/control.c +++ b/hypervisor/control.c @@ -990,58 +990,3 @@ long hypercall(unsigned long code, unsigned long arg1, unsigned long arg2) return -ENOSYS; } } - -/** - * Stops the current CPU on panic and prevents any execution on it until the - * system is rebooted. - * - * @note This service should be used when facing an unrecoverable error of the - * hypervisor. - * - * @see panic_park - */ -void __attribute__((noreturn)) panic_stop(void) -{ - struct cell *cell = this_cell(); - - panic_printk("Stopping CPU %d (Cell: \"%s\")\n", this_cpu_id(), - cell && cell->config ? cell->config->name : "<UNSET>"); - - if (phys_processor_id() == panic_cpu) - panic_in_progress = 0; - - arch_panic_stop(); -} - -/** - * Parks the current CPU on panic, allowing to restart it by resetting the - * cell's CPU state. - * - * @note This service should be used when facing an error of a cell CPU, e.g. a - * cell boundary violation. - * - * @see panic_stop - */ -void panic_park(void) -{ - struct cell *cell = this_cell(); - bool cell_failed = true; - unsigned int cpu; - - panic_printk("Parking CPU %d (Cell: \"%s\")\n", this_cpu_id(), - cell->config->name); - - this_cpu_public()->failed = true; - for_each_cpu(cpu, cell->cpu_set) - if (!public_per_cpu(cpu)->failed) { - cell_failed = false; - break; - } - if (cell_failed) - cell->comm_page.comm_region.cell_state = JAILHOUSE_CELL_FAILED; - - arch_panic_park(); - - if (phys_processor_id() == panic_cpu) - panic_in_progress = 0; -} diff --git a/hypervisor/include/jailhouse/control.h b/hypervisor/include/jailhouse/control.h index 2ac7e2dd..2d6eb930 100644 --- a/hypervisor/include/jailhouse/control.h +++ b/hypervisor/include/jailhouse/control.h @@ -22,9 +22,6 @@ #define INVALID_CPU_ID ~(0U) -extern volatile unsigned long panic_in_progress; -extern unsigned long panic_cpu; - /** * @defgroup Control Control Subsystem * @@ -131,9 +128,6 @@ long hypercall(unsigned long code, unsigned long arg1, unsigned long arg2); void shutdown(void); -void __attribute__((noreturn)) panic_stop(void); -void panic_park(void); - enum failure_mode {ABORT_ON_ERROR, WARN_ON_ERROR}; /** * (Re)Mapping of a cell memory into root cell upon loading and destroy. @@ -280,25 +274,6 @@ void arch_config_commit(struct cell *cell_added_removed); */ void arch_prepare_shutdown(void); -/** - * Performs the architecture-specifc steps to stop the current CPU on panic. - * - * @note This function never returns. - * - * @see panic_stop - */ -void __attribute__((noreturn)) arch_panic_stop(void); - -/** - * Performs the architecture-specific steps to park the current CPU on panic. - * - * @note This function only marks the CPU as parked and then returns to the - * caller. - * - * @see panic_park - */ -void arch_panic_park(void); - /** @} */ #endif diff --git a/hypervisor/include/jailhouse/panic.h b/hypervisor/include/jailhouse/panic.h new file mode 100644 index 00000000..a1df879c --- /dev/null +++ b/hypervisor/include/jailhouse/panic.h @@ -0,0 +1,40 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Copyright (c) Siemens AG, 2013 + * + * Authors: + * Jan Kiszka <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ +#ifndef _JAILHOUSE_PANIC_H +#define _JAILHOUSE_PANIC_H + +extern volatile unsigned long panic_in_progress; +extern unsigned long panic_cpu; + +void __attribute__((noreturn)) panic_stop(void); +void panic_park(void); + +/** + * Performs the architecture-specifc steps to stop the current CPU on panic. + * + * @note This function never returns. + * + * @see panic_stop + */ +void __attribute__((noreturn)) arch_panic_stop(void); + +/** + * Performs the architecture-specific steps to park the current CPU on panic. + * + * @note This function only marks the CPU as parked and then returns to the + * caller. + * + * @see panic_park + */ +void arch_panic_park(void); + +#endif diff --git a/hypervisor/include/jailhouse/printk.h b/hypervisor/include/jailhouse/printk.h index be1e861f..27bedcd0 100644 --- a/hypervisor/include/jailhouse/printk.h +++ b/hypervisor/include/jailhouse/printk.h @@ -9,6 +9,8 @@ * This work is licensed under the terms of the GNU GPL, version 2. See * the COPYING file in the top-level directory. */ +#ifndef _JAILHOUSE_PRINTK_H +#define _JAILHOUSE_PRINTK_H #include <jailhouse/types.h> @@ -30,3 +32,5 @@ extern void (*arch_dbg_write)(const char *msg); extern bool virtual_console; extern volatile struct jailhouse_virt_console console; + +#endif diff --git a/hypervisor/panic.c b/hypervisor/panic.c new file mode 100644 index 00000000..db911d78 --- /dev/null +++ b/hypervisor/panic.c @@ -0,0 +1,86 @@ +/* + * Jailhouse panic and assert functionalities. + * + * Copyright (c) Siemens AG, 2013-2016 + * + * Authors: + * Jan Kiszka <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ +#include <jailhouse/panic.h> +#include <jailhouse/assert.h> +#include <jailhouse/printk.h> +#include <jailhouse/percpu.h> +#include <jailhouse/control.h> +#include <jailhouse/processor.h> + +/** + * Stops the current CPU on panic and prevents any execution on it until the + * system is rebooted. + * + * @note This service should be used when facing an unrecoverable error of the + * hypervisor. + * + * @see panic_park + */ +void __attribute__((noreturn)) panic_stop(void) +{ + struct cell *cell = this_cell(); + + panic_printk("Stopping CPU %d (Cell: \"%s\")\n", this_cpu_id(), + cell && cell->config ? cell->config->name : "<UNSET>"); + + if (phys_processor_id() == panic_cpu) + panic_in_progress = 0; + + arch_panic_stop(); +} + +/** + * Parks the current CPU on panic, allowing to restart it by resetting the + * cell's CPU state. + * + * @note This service should be used when facing an error of a cell CPU, e.g. a + * cell boundary violation. + * + * @see panic_stop + */ +void panic_park(void) +{ + struct cell *cell = this_cell(); + bool cell_failed = true; + unsigned int cpu; + + panic_printk("Parking CPU %d (Cell: \"%s\")\n", this_cpu_id(), + cell->config->name); + + this_cpu_public()->failed = true; + for_each_cpu(cpu, cell->cpu_set) + if (!public_per_cpu(cpu)->failed) { + cell_failed = false; + break; + } + if (cell_failed) + cell->comm_page.comm_region.cell_state = JAILHOUSE_CELL_FAILED; + + arch_panic_park(); + + if (phys_processor_id() == panic_cpu) + panic_in_progress = 0; +} + +#ifdef CONFIG_DEBUG +/* debug-only runtime assertion */ +void __assert_fail( + const char *file, + unsigned int line, + const char *func, + const char *expr) +{ + panic_printk("%s:%u: %s assertion '%s' failed.\n", + file, line, func, expr); + panic_stop(); +} +#endif diff --git a/hypervisor/pci.c b/hypervisor/pci.c index 6934c33d..a0f6953c 100644 --- a/hypervisor/pci.c +++ b/hypervisor/pci.c @@ -16,6 +16,7 @@ #include <jailhouse/mmio.h> #include <jailhouse/pci.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <jailhouse/string.h> #include <jailhouse/unit.h> #include <jailhouse/utils.h> diff --git a/hypervisor/printk.c b/hypervisor/printk.c index 1b3027ba..d49e0a5c 100644 --- a/hypervisor/printk.c +++ b/hypervisor/printk.c @@ -13,6 +13,7 @@ #include <stdarg.h> #include <jailhouse/control.h> #include <jailhouse/printk.h> +#include <jailhouse/panic.h> #include <jailhouse/processor.h> #include <jailhouse/string.h> #include <asm/spinlock.h> diff --git a/hypervisor/uart.c b/hypervisor/uart.c index 6980970f..dd49adde 100644 --- a/hypervisor/uart.c +++ b/hypervisor/uart.c @@ -16,6 +16,7 @@ #include <jailhouse/uart.h> #include <jailhouse/control.h> #include <jailhouse/processor.h> +#include <jailhouse/panic.h> struct uart_chip *uart = NULL; -- 2.29.2 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jailhouse-dev/20210125120044.56794-12-andrea.bastoni%40tum.de.
