├── VERSION ├── pyjailhouse ├── __init__.py ├── extendedenum.py └── cell.py ├── Documentation ├── configuration-format.md ├── hypervisor-configuration.md ├── glossary.txt ├── coding-style.txt └── sysfs-entries.txt ├── inmates ├── tests │ ├── arm │ │ └── Makefile │ ├── arm64 │ │ └── Makefile │ └── x86 │ │ └── Makefile ├── lib │ ├── include │ │ ├── test.h │ │ └── string.h │ ├── test.c │ ├── arm64 │ │ ├── include │ │ │ └── arch │ │ │ │ └── gic.h │ │ └── Makefile │ ├── arm-common │ │ └── setup.c │ ├── arm │ │ └── Makefile │ ├── x86 │ │ └── uart.c │ └── alloc.c ├── tools │ ├── arm │ │ ├── Makefile │ │ └── linux-loader.c │ ├── arm64 │ │ ├── Makefile │ │ └── linux-loader.c │ └── x86 │ │ ├── Makefile │ │ └── linux-loader.c ├── demos │ ├── x86 │ │ ├── 32-bit-demo.c │ │ ├── tiny-demo.c │ │ ├── Makefile │ │ ├── smp-demo.c │ │ └── ioapic-demo.c │ ├── arm │ │ ├── Makefile │ │ ├── uart-demo.c │ │ └── gic-demo.c │ └── arm64 │ │ └── Makefile └── Makefile ├── hypervisor ├── arch │ ├── arm-common │ │ ├── include │ │ │ └── asm │ │ │ │ ├── mmio.h │ │ │ │ ├── ivshmem.h │ │ │ │ ├── setup.h │ │ │ │ ├── uart.h │ │ │ │ ├── paging_modes.h │ │ │ │ ├── traps.h │ │ │ │ ├── dcaches.h │ │ │ │ ├── cell.h │ │ │ │ ├── control.h │ │ │ │ ├── iommu.h │ │ │ │ ├── bitops.h │ │ │ │ ├── smccc.h │ │ │ │ ├── psci.h │ │ │ │ ├── gic.h │ │ │ │ └── gic_v2.h │ │ ├── Kbuild │ │ ├── lib.c │ │ ├── uart-xuartps.c │ │ ├── uart-imx.c │ │ ├── uart-mvebu.c │ │ ├── setup.c │ │ ├── dbg-write.c │ │ ├── uart-pl011.c │ │ ├── pci.c │ │ ├── uart-hscif.c │ │ ├── ivshmem.c │ │ └── uart-scifa.c │ ├── x86 │ │ ├── altc-8x16 │ │ ├── include │ │ │ └── asm │ │ │ │ ├── cat.h │ │ │ │ ├── sections.h │ │ │ │ ├── efifb.h │ │ │ │ ├── jailhouse_header.h │ │ │ │ ├── ivshmem.h │ │ │ │ ├── types.h │ │ │ │ ├── paging_modes.h │ │ │ │ ├── i8042.h │ │ │ │ ├── control.h │ │ │ │ ├── amd_iommu.h │ │ │ │ ├── pci.h │ │ │ │ ├── spinlock.h │ │ │ │ ├── io.h │ │ │ │ ├── mmio.h │ │ │ │ ├── iommu.h │ │ │ │ ├── cell.h │ │ │ │ └── bitops.h │ │ ├── Makefile │ │ ├── asm-defines.c │ │ ├── vmx-vmexit.S │ │ ├── iommu.c │ │ ├── svm-vmexit.S │ │ ├── i8042.c │ │ ├── Kbuild │ │ ├── dbg-write.c │ │ └── ivshmem.c │ ├── arm │ │ ├── include │ │ │ └── asm │ │ │ │ ├── types.h │ │ │ │ ├── jailhouse_header.h │ │ │ │ ├── mmu_hyp.h │ │ │ │ ├── entry.h │ │ │ │ ├── sections.h │ │ │ │ ├── percpu_fields.h │ │ │ │ ├── traps.h │ │ │ │ ├── smc.h │ │ │ │ ├── bitops.h │ │ │ │ ├── arch_gicv3.h │ │ │ │ ├── processor.h │ │ │ │ └── spinlock.h │ │ ├── Makefile │ │ ├── iommu.c │ │ ├── asm-defines.c │ │ ├── Kbuild │ │ ├── lib.c │ │ └── caches.S │ └── arm64 │ │ ├── include │ │ └── asm │ │ │ ├── types.h │ │ │ ├── memguard-data.h │ │ │ ├── jailhouse_header.h │ │ │ ├── percpu_fields.h │ │ │ ├── qos.h │ │ │ ├── entry.h │ │ │ ├── traps.h │ │ │ ├── arch_gicv3.h │ │ │ ├── sections.h │ │ │ ├── smc.h │ │ │ ├── bitops.h │ │ │ └── processor.h │ │ ├── Makefile │ │ ├── Kbuild │ │ ├── iommu.c │ │ ├── paging.c │ │ └── asm-defines.c ├── include │ └── jailhouse │ │ ├── processor.h │ │ ├── gcov.h │ │ ├── string.h │ │ ├── gen-defines.h │ │ ├── printk.h │ │ ├── uart.h │ │ ├── types.h │ │ ├── bitops.h │ │ ├── utils.h │ │ └── unit.h ├── uart.c ├── lib.c ├── hypervisor.lds.S └── gcov.c ├── ci ├── jailhouse-config.h ├── README.md ├── coverity_model.c ├── coverity-scan-build.sh └── build-all-configs.sh ├── include └── jailhouse │ ├── memguard-common.h │ ├── qos-common.h │ └── coloring-common.h ├── driver ├── vpci_template.dts ├── main.h ├── Makefile ├── sysfs.h ├── pci.h └── cell.h ├── .gitignore ├── scripts ├── gen_version_h ├── make_release ├── gen_pci_defs.sh └── include.mk ├── setup.py ├── configs ├── Makefile ├── arm64 │ ├── jetson-tx2-inmate-demo.c │ ├── jetson-tx1-inmate-demo.c │ ├── foundation-v8-inmate-demo.c │ ├── hikey-inmate-demo.c │ ├── espressobin-inmate-demo.c │ ├── macchiatobin-inmate-demo.c │ ├── zynqmp-zcu102-inmate-demo.c │ ├── miriac-sbc-ls1046a-inmate-demo.c │ ├── amd-seattle-inmate-demo.c │ ├── k3-am654-inmate-demo.c │ └── k3-j721e-evm-inmate-demo.c ├── x86 │ └── smp-demo.c └── arm │ ├── emtrion-rzg1h-inmate-demo.c │ ├── emtrion-rzg1m-inmate-demo.c │ └── emtrion-rzg1e-inmate-demo.c └── Makefile /VERSION: -------------------------------------------------------------------------------- 1 | v0.12 2 | -------------------------------------------------------------------------------- /pyjailhouse/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Documentation/configuration-format.md: -------------------------------------------------------------------------------- 1 | To be written... 2 | -------------------------------------------------------------------------------- /inmates/tests/arm/Makefile: -------------------------------------------------------------------------------- 1 | # nothing to do for now 2 | -------------------------------------------------------------------------------- /inmates/tests/arm64/Makefile: -------------------------------------------------------------------------------- 1 | # nothing to do for now 2 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/mmio.h: -------------------------------------------------------------------------------- 1 | /* nothing to do here */ 2 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/altc-8x16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rntmancuso/jailhouse-rt/HEAD/hypervisor/arch/x86/altc-8x16 -------------------------------------------------------------------------------- /ci/jailhouse-config.h: -------------------------------------------------------------------------------- 1 | #define CONFIG_TRACE_ERROR 1 2 | #define CONFIG_CRASH_CELL_ON_PANIC 1 3 | #define CONFIG_TEST_DEVICE 1 4 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/cat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2015 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | void cat_update(void); 14 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #define BITS_PER_LONG 32 14 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse AArch64 support 3 | * 4 | * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | * 6 | * Authors: 7 | * Dmitry Voytik 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #define BITS_PER_LONG 64 14 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse AArch64 support 3 | # 4 | # Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | # 6 | # Authors: 7 | # Antonios Motakis 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | LINUXINCLUDE += -I$(src)/arch/arm-common/include 14 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/memguard-data.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMGUARD_DATA_H 2 | #define MEMGUARD_DATA_H 3 | 4 | struct memguard { 5 | unsigned long start_time; 6 | unsigned long last_time; 7 | unsigned long pmu_evt_cnt; 8 | unsigned long budget_time; 9 | unsigned long budget_memory; 10 | unsigned long flags; 11 | bool memory_overrun; 12 | bool time_overrun; 13 | volatile u8 block; 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/sections.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | /* no special sections */ 14 | #define ARCH_SECTIONS 15 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/efifb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2018 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | void efifb_init(void); 14 | void efifb_write(const char *msg); 15 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2016 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | LINUXINCLUDE += -I$(src)/arch/arm-common/include 14 | 15 | KBUILD_CFLAGS += -marm -march=armv7ve 16 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/jailhouse_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (C) Siemens AG, 2017 5 | * 6 | * Authors: 7 | * Henning Schild 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #define JAILHOUSE_BASE __JH_CONST_UL(0xffffc0200000) 14 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/processor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | unsigned long phys_processor_id(void); 16 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/ivshmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2016 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | struct arch_ivshmem_irq_cache { 14 | u16 id[IVSHMEM_MSIX_VECTORS]; 15 | }; 16 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/jailhouse_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (C) Siemens AG, 2017 5 | * 6 | * Authors: 7 | * Henning Schild 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #define JAILHOUSE_BASE 0xf0000000 14 | #define JAILHOUSE_BORROW_ROOT_PT 1 15 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/jailhouse_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (C) Siemens AG, 2017 5 | * 6 | * Authors: 7 | * Henning Schild 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #define JAILHOUSE_BASE __JH_CONST_UL(0xfffffffff0000000) 14 | #define JAILHOUSE_BORROW_ROOT_PT 1 15 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/setup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2017 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | int arm_init_early(void); 16 | int arm_cpu_init(struct per_cpu *cpu_data); 17 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/gcov.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2017 5 | * 6 | * Authors: 7 | * Henning Schild 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifdef CONFIG_JAILHOUSE_GCOV 14 | void gcov_init(void); 15 | #else 16 | static inline void gcov_init(void) {} 17 | #endif 18 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/ivshmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2016 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | struct arch_ivshmem_irq_cache { 16 | struct apic_irq_message msg[IVSHMEM_MSIX_VECTORS]; 17 | }; 18 | -------------------------------------------------------------------------------- /inmates/lib/include/test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Jailhouse, a Linux-based partitioning hypervisor 4 | * 5 | * Copyright (c) Siemens AG, 2018 6 | * 7 | * Authors: 8 | * Jan Kiszka 9 | * 10 | * This work is licensed under the terms of the GNU GPL, version 2. See 11 | * the COPYING file in the top-level directory. 12 | */ 13 | 14 | #define EXPECT_EQUAL(a, b) __evaluate(a, b, __LINE__) 15 | 16 | extern bool all_passed; 17 | 18 | void __evaluate(u64 a, u64 b, int line); 19 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | /** 14 | * @defgroup X86 x86 Architecture 15 | * 16 | * Documentation for the x86 processor architecture. 17 | */ 18 | 19 | #define BITS_PER_LONG 64 20 | -------------------------------------------------------------------------------- /inmates/tools/arm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013-2015 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | include $(INMATES_LIB)/Makefile.lib 14 | 15 | INMATES := linux-loader.bin 16 | 17 | linux-loader-y := linux-loader.o 18 | 19 | $(eval $(call DECLARE_TARGETS,$(INMATES))) 20 | -------------------------------------------------------------------------------- /inmates/tools/arm64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013-2015 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | include $(INMATES_LIB)/Makefile.lib 14 | 15 | INMATES := linux-loader.bin 16 | 17 | linux-loader-y := linux-loader.o 18 | 19 | $(eval $(call DECLARE_TARGETS,$(INMATES))) 20 | -------------------------------------------------------------------------------- /inmates/tools/x86/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013-2015 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | include $(INMATES_LIB)/Makefile.lib 14 | 15 | INMATES := linux-loader.bin 16 | 17 | linux-loader-y := linux-loader.o 18 | 19 | $(eval $(call DECLARE_TARGETS,$(INMATES))) 20 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) OTH Regensburg, 2017 5 | * 6 | * Authors: 7 | * Ralf Ramsauer 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | extern struct uart_chip uart_pl011_ops, uart_xuartps_ops, uart_mvebu_ops, 14 | uart_hscif_ops, uart_scifa_ops, uart_imx_ops, uart_s32_ops; 15 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/paging_modes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | extern const struct paging x86_64_paging[]; 16 | extern const struct paging pae_paging[]; 17 | extern const struct paging i386_paging[]; 18 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/paging_modes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef __ASSEMBLY__ 14 | 15 | #include 16 | 17 | /* Long-descriptor paging */ 18 | extern const struct paging *cell_paging; 19 | 20 | #endif /* !__ASSEMBLY__ */ 21 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/percpu_fields.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2018 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | #define ARCH_PERCPU_FIELDS \ 16 | ARM_PERCPU_FIELDS \ 17 | struct memguard memguard; \ 18 | unsigned long id_aa64mmfr0; 19 | 20 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/mmu_hyp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | int switch_exception_level(struct per_cpu *cpu_data); 16 | 17 | void __attribute__((noreturn)) arch_shutdown_mmu(struct per_cpu *cpu_data); 18 | -------------------------------------------------------------------------------- /inmates/demos/x86/32-bit-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * 13 | * Use with tiny-demo config e.g. 14 | */ 15 | 16 | #include 17 | 18 | #define IA32_EFER 0xc0000080 19 | 20 | void inmate_main(void) 21 | { 22 | printk("This runs in 32-bit mode (EFER: %llx)\n", read_msr(IA32_EFER)); 23 | } 24 | -------------------------------------------------------------------------------- /include/jailhouse/memguard-common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MemGuard Support for Jailhouse 3 | * 4 | * Copyright (c) Boston University, 2020 5 | * 6 | * Authors: 7 | * Renato Mancuso 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. 10 | * See the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_MEMGUARD_COMMON_H 14 | #define _JAILHOUSE_MEMGUARD_COMMON_H 15 | 16 | struct memguard_params { 17 | unsigned long budget_time; 18 | unsigned long budget_memory; 19 | unsigned long flags; 20 | }; 21 | 22 | #endif /* _JAILHOUSE_MEMGUARD_COMMON_H */ 23 | 24 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/qos.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ARM QoS Support for Jailhouse 3 | * 4 | * Copyright (c) Boston University, 2020 5 | * 6 | * Authors: 7 | * Renato Mancuso 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. 10 | * See the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_QOS_H 14 | #define _JAILHOUSE_ASM_QOS_H 15 | 16 | #include 17 | 18 | /* Main entry point for QoS management call */ 19 | int qos_call(unsigned long count, unsigned long settings_ptr); 20 | 21 | #endif /* _JAILHOUSE_ASM_QOS_H */ 22 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/entry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * Copyright (c) Siemens AG, 2017 6 | * 7 | * Authors: 8 | * Jean-Philippe Brucker 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #include 16 | 17 | extern unsigned long bootstrap_vectors; 18 | extern unsigned long hyp_vectors; 19 | 20 | void __attribute__((noreturn)) vmreturn(union registers *guest_regs); 21 | -------------------------------------------------------------------------------- /inmates/demos/arm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) ARM Limited, 2014 5 | # 6 | # Authors: 7 | # Jean-Philippe Brucker 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | include $(INMATES_LIB)/Makefile.lib 14 | 15 | INMATES := gic-demo.bin uart-demo.bin ivshmem-demo.bin mem-bomb.bin 16 | 17 | gic-demo-y := gic-demo.o 18 | uart-demo-y := uart-demo.o 19 | ivshmem-demo-y := ../ivshmem-demo.o 20 | mem-bomb-y := mem-bomb.o 21 | 22 | $(eval $(call DECLARE_TARGETS,$(INMATES))) 23 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/sections.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * Copyright (c) Siemens AG, 2014 6 | * 7 | * Authors: 8 | * Jean-Philippe Brucker 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #define ARCH_SECTIONS \ 16 | . = ALIGN(PAGE_SIZE); \ 17 | .trampoline : { \ 18 | trampoline_start = .; \ 19 | *(.trampoline) \ 20 | trampoline_end = .; \ 21 | } 22 | -------------------------------------------------------------------------------- /include/jailhouse/qos-common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ARM QoS Support for Jailhouse 3 | * 4 | * Copyright (c) Boston University, 2020 5 | * 6 | * Authors: 7 | * Renato Mancuso 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. 10 | * See the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_QOS_COMMON_H 14 | #define _JAILHOUSE_QOS_COMMON_H 15 | 16 | #define QOS_DEV_NAMELEN 15 17 | #define QOS_PARAM_NAMELEN 16 18 | 19 | struct qos_setting { 20 | char dev_name [QOS_DEV_NAMELEN]; 21 | char param_name [QOS_PARAM_NAMELEN]; 22 | __u32 value; 23 | }; 24 | 25 | #endif /* _JAILHOUSE_QOS_COMMON_H */ 26 | -------------------------------------------------------------------------------- /driver/vpci_template.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | / { 3 | fragment { 4 | target-path = "/"; 5 | __overlay__ { 6 | pci@0 { 7 | compatible = "pci-host-ecam-generic"; 8 | /* 9 | * added dynamically: 10 | * - device_type = "pci" 11 | * - linux,pci-domain = <...> 12 | * - reg = <...> 13 | * - ranges = <...> 14 | * - interrupt-map = <...> 15 | */ 16 | bus-range = <0 0>; 17 | #address-cells = <3>; 18 | #size-cells = <2>; 19 | #interrupt-cells = <1>; 20 | interrupt-map-mask = <0 0 0 7>; 21 | dma-coherent; 22 | /* set to "ok" during dynamic update */ 23 | status = "disabled"; 24 | }; 25 | }; 26 | }; 27 | }; 28 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013-2016 5 | # Copyright (c) Valentine Sinitsyn, 2014 6 | # 7 | # Authors: 8 | # Jan Kiszka 9 | # Valentine Sinitsyn 10 | # 11 | # This work is licensed under the terms of the GNU GPL, version 2. See 12 | # the COPYING file in the top-level directory. 13 | # 14 | 15 | KBUILD_CFLAGS += -mcmodel=kernel -mno-sse -mno-mmx -mno-sse2 -mno-3dnow 16 | KBUILD_CFLAGS += -mno-red-zone 17 | KBUILD_CFLAGS += $(call cc-option,-mno-avx,) 18 | 19 | KBUILD_CPPFLAGS += -m64 20 | 21 | BUILD_VARIANTS := amd intel 22 | -------------------------------------------------------------------------------- /inmates/demos/arm64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse AArch64 support 3 | # 4 | # Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | # 6 | # Authors: 7 | # Antonios Motakis 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | include $(INMATES_LIB)/Makefile.lib 14 | 15 | INMATES := gic-demo.bin uart-demo.bin ivshmem-demo.bin mem-bomb.bin 16 | 17 | gic-demo-y := ../arm/gic-demo.o 18 | uart-demo-y := ../arm/uart-demo.o 19 | ivshmem-demo-y := ../ivshmem-demo.o 20 | mem-bomb-y := ../arm/mem-bomb.o 21 | 22 | $(eval $(call DECLARE_TARGETS,$(INMATES))) 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build outputs - only! 2 | *.[oa] 3 | *.mod 4 | *.mod.[co] 5 | *.cell 6 | *.cmd 7 | *.bin 8 | *.gcno 9 | *.gcda 10 | .tmp_versions 11 | *.dtb 12 | *.dtb.S 13 | *.dtb.*.tmp 14 | *.8 15 | .cache.mk 16 | Module.symvers 17 | modules.order 18 | driver/jailhouse.ko 19 | include/jailhouse/config.h 20 | hypervisor/hypervisor.lds 21 | inmates/lib/arm/inmate.lds 22 | inmates/lib/arm64/inmate.lds 23 | pyjailhouse/pci_defs.py 24 | tools/ivshmem-demo 25 | tools/jailhouse 26 | tools/jailhouse-gcov-extract 27 | tools/jailhouse-config-collect 28 | Documentation/generated 29 | hypervisor/include/generated 30 | hypervisor/arch/*/include/generated 31 | *.s 32 | ci/out 33 | ci/*.tar.xz 34 | *.pyc 35 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/traps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) OTH Regensburg, 2018 5 | * 6 | * Authors: 7 | * Ralf Ramsauer 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | enum trap_return { 14 | TRAP_HANDLED = 1, 15 | TRAP_UNHANDLED = 0, 16 | TRAP_FORBIDDEN = -1, 17 | }; 18 | 19 | typedef enum trap_return (*trap_handler)(struct trap_context *ctx); 20 | 21 | void arch_skip_instruction(struct trap_context *ctx); 22 | 23 | enum trap_return arch_handle_dabt(struct trap_context *ctx); 24 | -------------------------------------------------------------------------------- /inmates/lib/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Jailhouse, a Linux-based partitioning hypervisor 4 | * 5 | * Copyright (c) Siemens AG, 2018 6 | * 7 | * Authors: 8 | * Jan Kiszka 9 | * 10 | * This work is licensed under the terms of the GNU GPL, version 2. See 11 | * the COPYING file in the top-level directory. 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | bool all_passed = true; 18 | 19 | void __evaluate(u64 a, u64 b, int line) 20 | { 21 | bool passed = (a == b); 22 | 23 | printk("Test at line #%d %s\n", line, passed ? "passed" : "FAILED"); 24 | if (!passed) { 25 | printk(" %llx != %llx\n", (u64)a, (u64)b); 26 | all_passed = false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ci/README.md: -------------------------------------------------------------------------------- 1 | Jailhouse Continuous Integration Build Environment 2 | ================================================== 3 | 4 | This collects tools and generates the Linux kernel binaries required to build 5 | Jailhouse in continuous integration environments. Currently, travis-ci.org is 6 | the target environment. 7 | 8 | How to use 9 | ---------- 10 | 11 | - Prepare an Ubuntu system according to the 12 | [travis-ci specifications](http://docs.travis-ci.com/user/ci-environment) 13 | or via the [Chef recipes](https://github.com/travis-ci/travis-cookbooks). 14 | - Run gen-kernel-build.sh on that system. 15 | - Upload ci/out/kernel-build.tar.xz to the location where Jailhouse's 16 | .travis.yml expects it. 17 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/i8042.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_I8042_H 14 | #define _JAILHOUSE_ASM_I8042_H 15 | 16 | #include 17 | 18 | #define I8042_CMD_REG 0x64 19 | # define I8042_CMD_WRITE_CTRL_PORT 0xd1 20 | # define I8042_CMD_PULSE_CTRL_PORT 0xf0 21 | 22 | int i8042_access_handler(u16 port, bool dir_in, unsigned int size); 23 | 24 | #endif /* !_JAILHOUSE_ASM_I8042_H */ 25 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/control.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | struct exception_frame; 16 | 17 | enum x86_init_sipi { X86_INIT, X86_SIPI }; 18 | 19 | void x86_send_init_sipi(unsigned int cpu_id, enum x86_init_sipi type, 20 | int sipi_vector); 21 | 22 | void x86_check_events(void); 23 | 24 | void __attribute__((noreturn)) 25 | x86_exception_handler(struct exception_frame *frame); 26 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/entry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse AArch64 support 3 | * 4 | * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | * Copyright (c) Siemens AG, 2017 6 | * 7 | * Authors: 8 | * Antonios Motakis 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #include 16 | 17 | extern unsigned long hyp_vectors_hardened; 18 | 19 | void enable_mmu_el2(u64 ttbr0_el2); 20 | void __attribute__((noreturn)) shutdown_el2(struct per_cpu *cpu_data); 21 | 22 | void __attribute__((noreturn)) vmreturn(union registers *guest_regs); 23 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/percpu_fields.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2018 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #define NUM_ENTRY_REGS 13 14 | 15 | #define ARCH_PERCPU_FIELDS \ 16 | ARM_PERCPU_FIELDS \ 17 | /** Linux stack pointer, used for handover to the hypervisor. */ \ 18 | unsigned long linux_sp; \ 19 | unsigned long linux_ret; \ 20 | unsigned long linux_flags; \ 21 | unsigned long linux_reg[NUM_ENTRY_REGS]; \ 22 | \ 23 | bool initialized; 24 | -------------------------------------------------------------------------------- /inmates/demos/arm/uart-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | void inmate_main(void) 16 | { 17 | unsigned int i = 0, j; 18 | /* 19 | * The cell config can set up a mapping to access UARTx instead of UART0 20 | */ 21 | while(++i) { 22 | for (j = 0; j < 100000000; j++); 23 | printk("Hello %d from cell!\n", i); 24 | } 25 | 26 | /* lr should be 0, so a return will go back to the reset vector */ 27 | } 28 | -------------------------------------------------------------------------------- /scripts/gen_version_h: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Jailhouse, a Linux-based partitioning hypervisor 4 | # 5 | # Copyright (c) Siemens AG, 2014 6 | # 7 | # Authors: 8 | # Jan Kiszka 9 | # 10 | # This work is licensed under the terms of the GNU GPL, version 2. See 11 | # the COPYING file in the top-level directory. 12 | # 13 | 14 | echo "/* Auto-generated - leave alone and don't commit! */" 15 | echo "" 16 | 17 | cd "$1" > /dev/null 18 | 19 | if ! git rev-parse 2>/dev/null; then 20 | version="`cat VERSION`" 21 | else 22 | describe="`git describe --long --dirty --match "v[0-9].[0-9]*"`" 23 | version="`echo $describe | sed -e 's/\([^-]*\)-\(.*\)/\1 (\2)/'`" 24 | fi 25 | 26 | cd - > /dev/null 27 | 28 | echo "#define JAILHOUSE_VERSION \"$version\"" 29 | -------------------------------------------------------------------------------- /inmates/demos/x86/tiny-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | void inmate_main(void) 16 | { 17 | unsigned long long start, now; 18 | int n; 19 | 20 | printk("Hello from this tiny cell!\n"); 21 | 22 | start = pm_timer_read(); 23 | for (n = 0; n < 10; n++) { 24 | do { 25 | now = pm_timer_read(); 26 | cpu_relax(); 27 | } while (now - start < 1000000000ULL); 28 | start += 1000000000ULL; 29 | printk("PM Timer: %11llu\n", now); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | void *memcpy(void *d, const void *s, unsigned long n); 14 | void *memset(void *s, int c, unsigned long n); 15 | 16 | int strcmp(const char *s1, const char *s2); 17 | int strncmp(const char *s1, const char *s2, unsigned long n); 18 | 19 | /* 20 | * Indirect stringification. Doing two levels allows the parameter to be a 21 | * macro itself. 22 | */ 23 | 24 | #define __stringify_1(x...) #x 25 | #define __stringify(x...) __stringify_1(x) 26 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/traps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_TRAPS_H 14 | #define _JAILHOUSE_ASM_TRAPS_H 15 | 16 | #include 17 | 18 | struct trap_context { 19 | unsigned long *regs; 20 | u32 hsr; 21 | }; 22 | 23 | void access_cell_reg(struct trap_context *ctx, u8 reg, unsigned long *val, 24 | bool is_read); 25 | 26 | /* now include from arm-common */ 27 | #include_next 28 | 29 | #endif /* !_JAILHOUSE_ASM_TRAPS_H */ 30 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/Kbuild: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013-2017 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | -include $(GEN_CONFIG_MK) 14 | 15 | ccflags-$(CONFIG_JAILHOUSE_GCOV) += -fprofile-arcs -ftest-coverage 16 | 17 | objs-y += dbg-write.o lib.o psci.o control.o paging.o mmu_cell.o setup.o 18 | objs-y += irqchip.o pci.o ivshmem.o uart-pl011.o uart-xuartps.o uart-mvebu.o 19 | objs-y += uart-hscif.o uart-scifa.o uart-imx.o uart-s32.o 20 | objs-y += gic-v2.o gic-v3.o smccc.o 21 | # objs-y += coloring.o 22 | 23 | common-objs-y = $(addprefix ../arm-common/,$(objs-y)) 24 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # 2 | # pyjailhouse, a python interface for the Jailhouse hypervisor 3 | # 4 | # Copyright (c) Christopher Goldsworthy, 2018 5 | # 6 | # This script is used to create project metadata when installing pyjailhouse 7 | # using pip. 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | from setuptools import setup, find_packages 14 | 15 | with open("VERSION") as version_file: 16 | version = version_file.read().lstrip("v") 17 | 18 | setup(name="pyjailhouse", version=version, 19 | description="A Python interface for the Jailhouse Hypervisor", 20 | license="GPLv2", url="https://github.com/siemens/jailhouse", 21 | author_email="jailhouse-dev@googlegroups.com", 22 | packages=find_packages()) 23 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/Kbuild: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse AArch64 support 3 | # 4 | # Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | # Copyright (c) Siemens AG, 2016 6 | # 7 | # Authors: 8 | # Antonios Motakis 9 | # Jan Kiszka 10 | # 11 | # This work is licensed under the terms of the GNU GPL, version 2. See 12 | # the COPYING file in the top-level directory. 13 | # 14 | 15 | include $(src)/../arm-common/Kbuild 16 | 17 | always := lib.a 18 | 19 | # units initialization order as defined by linking order: 20 | # irqchip (common-objs-y), 21 | 22 | lib-y := $(common-objs-y) 23 | lib-y += entry.o setup.o control.o mmio.o paging.o caches.o traps.o 24 | lib-y += iommu.o smmu-v2.o smmu-v3.o ti-pvu.o coloring.o 25 | lib-y += memguard.o 26 | lib-y += qos.o 27 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/iommu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) 2018 Texas Instruments Incorporated - http://www.ti.com 5 | * 6 | * Authors: 7 | * Nikhil Devshatwar 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | unsigned int iommu_count_units(void) 16 | { 17 | return 0; 18 | } 19 | 20 | int iommu_map_memory_region(struct cell *cell, 21 | const struct jailhouse_memory *mem) 22 | { 23 | return 0; 24 | } 25 | 26 | int iommu_unmap_memory_region(struct cell *cell, 27 | const struct jailhouse_memory *mem) 28 | { 29 | return 0; 30 | } 31 | 32 | void iommu_config_commit(struct cell *cell) 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/traps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse AArch64 support 3 | * 4 | * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | * 6 | * Authors: 7 | * Antonios Motakis 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_TRAPS_H 14 | #define _JAILHOUSE_ASM_TRAPS_H 15 | 16 | #include 17 | 18 | struct trap_context { 19 | unsigned long *regs; 20 | u64 esr; 21 | u64 spsr; 22 | u64 sp; 23 | }; 24 | 25 | void arch_handle_trap(union registers *guest_regs); 26 | void arch_el2_abt(union registers *regs); 27 | 28 | /* now include from arm-common */ 29 | #include_next 30 | 31 | #endif /* !_JAILHOUSE_ASM_TRAPS_H */ 32 | -------------------------------------------------------------------------------- /driver/main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2017 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_DRIVER_MAIN_H 14 | #define _JAILHOUSE_DRIVER_MAIN_H 15 | 16 | #include 17 | 18 | #include "cell.h" 19 | 20 | extern struct mutex jailhouse_lock; 21 | extern bool jailhouse_enabled; 22 | extern void *hypervisor_mem; 23 | 24 | void *jailhouse_ioremap(phys_addr_t phys, unsigned long virt, 25 | unsigned long size); 26 | int jailhouse_console_dump_delta(char *dst, unsigned int head, 27 | unsigned int *miss); 28 | 29 | #endif /* !_JAILHOUSE_DRIVER_MAIN_H */ 30 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/dcaches.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * Copyright (c) Siemens AG, 2017 6 | * 7 | * Authors: 8 | * Jean-Philippe Brucker 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #ifndef __ASSEMBLY__ 16 | 17 | struct cell; 18 | 19 | enum dcache_flush { 20 | DCACHE_CLEAN, 21 | DCACHE_INVALIDATE, 22 | DCACHE_CLEAN_AND_INVALIDATE, 23 | }; 24 | 25 | void arm_dcaches_flush(void *addr, long size, enum dcache_flush flush); 26 | void arm_cell_dcaches_flush(struct cell *cell, enum dcache_flush flush); 27 | void arm_l1l2_caches_flush(void); 28 | 29 | #endif /* !__ASSEMBLY__ */ 30 | -------------------------------------------------------------------------------- /inmates/tests/x86/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013-2018 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | include $(INMATES_LIB)/Makefile.lib 14 | 15 | INMATES := mmio-access.bin mmio-access-32.bin sse-demo.bin sse-demo-32.bin 16 | 17 | mmio-access-y := mmio-access.o 18 | 19 | $(eval $(call DECLARE_32_BIT,mmio-access-32)) 20 | mmio-access-32-y := mmio-access-32.o 21 | 22 | sse-demo-y := sse-demo.o 23 | 24 | $(eval $(call DECLARE_32_BIT,sse-demo-32)) 25 | sse-demo-32-y := sse-demo-32.o 26 | 27 | $(obj)/sse-demo-32.o: $(src)/sse-demo.c FORCE 28 | $(call if_changed_rule,cc_o_c) 29 | 30 | $(eval $(call DECLARE_TARGETS,$(INMATES))) 31 | -------------------------------------------------------------------------------- /ci/coverity_model.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2015 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #define __MODEL_GFP_USER (0x10u | 0x40u | 0x80u | 0x20000u) 14 | #define __MODEL_GFP_NOWARN 0x200u 15 | 16 | void *kmalloc(size_t size, unsigned flags) 17 | { 18 | void *ptr; 19 | 20 | if (flags == (__MODEL_GFP_USER | __MODEL_GFP_NOWARN)) 21 | __coverity_tainted_data_sanitize__(size); 22 | else 23 | __coverity_tainted_data_sink__(size); 24 | 25 | ptr = __coverity_alloc__(size); 26 | 27 | __coverity_mark_as_uninitialized_buffer__(ptr); 28 | __coverity_mark_as_afm_allocated__(ptr, "kfree"); 29 | 30 | return ptr; 31 | } 32 | -------------------------------------------------------------------------------- /driver/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013-2015 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # Benjamin Block 9 | # 10 | # This work is licensed under the terms of the GNU GPL, version 2. See 11 | # the COPYING file in the top-level directory. 12 | # 13 | 14 | obj-m := jailhouse.o 15 | 16 | ccflags-y := -I$(src)/../hypervisor/arch/$(SRCARCH)/include \ 17 | -I$(src)/../hypervisor/include \ 18 | -I$(src)/../include/arch/$(SRCARCH) \ 19 | -I$(src)/../include 20 | 21 | jailhouse-y := cell.o main.o sysfs.o 22 | jailhouse-$(CONFIG_PCI) += pci.o 23 | jailhouse-$(CONFIG_OF) += vpci_template.dtb.o 24 | 25 | targets += vpci_template.dtb vpci_template.dtb.S 26 | 27 | .SECONDARY: \ 28 | $(obj)/vpci_template.dtb.S \ 29 | $(obj)/vpci_template.dtb 30 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/cell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2016 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_CELL_H 14 | #define _JAILHOUSE_ASM_CELL_H 15 | 16 | #include 17 | 18 | struct pvu_tlb_entry; 19 | 20 | struct arch_cell { 21 | struct paging_structures mm; 22 | 23 | u32 irq_bitmap[1024/32]; 24 | 25 | union { 26 | struct { 27 | u8 ent_count; 28 | struct pvu_tlb_entry *entries; 29 | } iommu_pvu; /**< ARM PVU specific fields. */ 30 | 31 | /* For SMMUv2 and SMMUv3 */ 32 | struct paging_structures iomm; 33 | }; 34 | }; 35 | 36 | #endif /* !_JAILHOUSE_ASM_CELL_H */ 37 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/gen-defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Valentine Sinitsyn, 2014 5 | * 6 | * Authors: 7 | * Valentine Sinitsyn 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * Derived from linux/include/linux/kbuild.h: 13 | * 14 | * Copyright (c) Linux kernel developers, 2014 15 | */ 16 | 17 | #ifndef _JAILHOUSE_GEN_DEFINES_H 18 | #define _JAILHOUSE_GEN_DEFINES_H 19 | 20 | #define DEFINE(sym, val) \ 21 | asm volatile("\n=>" #sym " %0 " #val : : "i" (val)) 22 | 23 | #define BLANK() asm volatile("\n=>" : : ) 24 | 25 | #define OFFSET(sym, str, mem) \ 26 | DEFINE(sym, __builtin_offsetof(struct str, mem)) 27 | 28 | #define COMMENT(x) \ 29 | asm volatile("\n=>#" x) 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /inmates/demos/x86/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013, 2014 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | include $(INMATES_LIB)/Makefile.lib 14 | 15 | INMATES := tiny-demo.bin apic-demo.bin ioapic-demo.bin 32-bit-demo.bin \ 16 | pci-demo.bin e1000-demo.bin ivshmem-demo.bin smp-demo.bin 17 | 18 | tiny-demo-y := tiny-demo.o 19 | apic-demo-y := apic-demo.o 20 | ioapic-demo-y := ioapic-demo.o 21 | pci-demo-y := pci-demo.o 22 | e1000-demo-y := e1000-demo.o 23 | ivshmem-demo-y := ../ivshmem-demo.o 24 | smp-demo-y := smp-demo.o 25 | 26 | $(eval $(call DECLARE_32_BIT,32-bit-demo)) 27 | 32-bit-demo-y := 32-bit-demo.o 28 | 29 | $(eval $(call DECLARE_TARGETS,$(INMATES))) 30 | -------------------------------------------------------------------------------- /driver/sysfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014-2017 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_DRIVER_SYSFS_H 14 | #define _JAILHOUSE_DRIVER_SYSFS_H 15 | 16 | #include 17 | 18 | int jailhouse_sysfs_cell_create(struct cell *cell); 19 | void jailhouse_sysfs_cell_register(struct cell *cell); 20 | void jailhouse_sysfs_cell_delete(struct cell *cell); 21 | 22 | int jailhouse_sysfs_core_init(struct device *dev, size_t hypervisor_size); 23 | void jailhouse_sysfs_core_exit(struct device *dev); 24 | int jailhouse_sysfs_init(struct device *dev); 25 | void jailhouse_sysfs_exit(struct device *dev); 26 | 27 | #endif /* !_JAILHOUSE_DRIVER_SYSFS_H */ 28 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | unsigned long phys_processor_id(void) 19 | { 20 | unsigned long mpidr; 21 | 22 | arm_read_sysreg(MPIDR_EL1, mpidr); 23 | return mpidr & MPIDR_CPUID_MASK; 24 | } 25 | 26 | unsigned int arm_cpu_by_mpidr(struct cell *cell, unsigned long mpidr) 27 | { 28 | unsigned int cpu; 29 | 30 | for_each_cpu(cpu, cell->cpu_set) 31 | if (mpidr == (public_per_cpu(cpu)->mpidr & MPIDR_CPUID_MASK)) 32 | return cpu; 33 | 34 | return -1; 35 | } 36 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/asm-defines.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Valentine Sinitsyn, 2014 5 | * 6 | * Authors: 7 | * Valentine Sinitsyn 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void common(void); 18 | 19 | void common(void) 20 | { 21 | OFFSET(PERCPU_LINUX_SP, per_cpu, linux_sp); 22 | BLANK(); 23 | 24 | /* GCC evaluates constant expressions involving built-ins 25 | * at compilation time, so this yields computed value. 26 | */ 27 | DEFINE(PERCPU_STACK_END, 28 | __builtin_offsetof(struct per_cpu, stack) + \ 29 | FIELD_SIZEOF(struct per_cpu, stack)); 30 | DEFINE(PERCPU_SIZE_ASM, sizeof(struct per_cpu)); 31 | } 32 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/Kbuild: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013-2016 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | include $(src)/../arm-common/Kbuild 14 | 15 | always := lib.a 16 | 17 | # units initialization order as defined by linking order: 18 | # irqchip (common-objs-y), 19 | 20 | lib-y := $(common-objs-y) 21 | lib-y += entry.o setup.o control.o traps.o mmio.o lib.o 22 | lib-y += mmu_hyp.o caches.o iommu.o 23 | 24 | # in here we switch of the MMU and stuff, cant profile such code 25 | # NOTE 26 | # gcc7 will bring a new function attribute "no_profile_instrument_function" 27 | # should switch to that for higher granularity, but gcc7 is not even there 28 | CFLAGS_mmu_hyp.o += -fno-profile-arcs -fno-test-coverage 29 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/uart-xuartps.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2016 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #define UART_SR 0x2c 17 | #define UART_SR_TXEMPTY 0x8 18 | #define UART_FIFO 0x30 19 | 20 | static void uart_init(struct uart_chip *chip) 21 | { 22 | } 23 | 24 | static bool uart_is_busy(struct uart_chip *chip) 25 | { 26 | return !(mmio_read32(chip->virt_base + UART_SR) & UART_SR_TXEMPTY); 27 | } 28 | 29 | static void uart_write_char(struct uart_chip *chip, char c) 30 | { 31 | mmio_write32(chip->virt_base + UART_FIFO, c); 32 | } 33 | 34 | struct uart_chip uart_xuartps_ops = { 35 | .init = uart_init, 36 | .is_busy = uart_is_busy, 37 | .write_char = uart_write_char, 38 | }; 39 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/smc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (C) 2018 OTH Regensburg 5 | * 6 | * Authors: 7 | * Ralf Ramsauer 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | /* for gcc < 5 */ 14 | asm (".arch_extension sec\n"); 15 | 16 | static inline int smc(unsigned long id) 17 | { 18 | register unsigned long __id asm("r0") = id; 19 | 20 | asm volatile ("smc #0\n\t" 21 | : "=r" (__id) 22 | : "r"(__id) 23 | : "memory", "r1", "r2", "r3"); 24 | 25 | return __id; 26 | } 27 | 28 | static inline int smc_arg1(unsigned long id, unsigned long par1) 29 | { 30 | register unsigned long __id asm("r0") = id; 31 | register unsigned long __par1 asm("r1") = par1; 32 | 33 | asm volatile ("smc #0\n\t" 34 | : "=r" (__id) 35 | : "r"(__id), "r"(__par1) 36 | : "memory", "r2", "r3"); 37 | 38 | return __id; 39 | } 40 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/uart-imx.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright 2017 NXP 5 | * 6 | * Authors: 7 | * Peng Fan 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #define UTS 0xb4 17 | #define UTXD 0x40 18 | #define UTS_TXEMPTY (1 << 6) 19 | 20 | static void uart_init(struct uart_chip *chip) 21 | { 22 | /* Initialization currently done by Linux */ 23 | } 24 | 25 | static bool uart_is_busy(struct uart_chip *chip) 26 | { 27 | return !(mmio_read32(chip->virt_base + UTS) & UTS_TXEMPTY); 28 | } 29 | 30 | static void uart_write_char(struct uart_chip *chip, char c) 31 | { 32 | mmio_write32(chip->virt_base + UTXD, c); 33 | } 34 | 35 | struct uart_chip uart_imx_ops = { 36 | .init = uart_init, 37 | .is_busy = uart_is_busy, 38 | .write_char = uart_write_char, 39 | }; 40 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/uart-mvebu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2017 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #define UART_TSH 0x4 17 | #define UART_STAT 0xc 18 | #define UART_STAT_TX_FULL (1 << 11) 19 | 20 | static void uart_init(struct uart_chip *chip) 21 | { 22 | } 23 | 24 | static bool uart_is_busy(struct uart_chip *chip) 25 | { 26 | return !!(mmio_read32(chip->virt_base + UART_STAT) & UART_STAT_TX_FULL); 27 | } 28 | 29 | static void uart_write_char(struct uart_chip *chip, char c) 30 | { 31 | mmio_write32(chip->virt_base + UART_TSH, c); 32 | } 33 | 34 | struct uart_chip uart_mvebu_ops = { 35 | .init = uart_init, 36 | .is_busy = uart_is_busy, 37 | .write_char = uart_write_char, 38 | }; 39 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/printk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | void __attribute__((format(printf, 1, 2))) printk(const char *fmt, ...); 16 | 17 | void __attribute__((format(printf, 1, 2))) panic_printk(const char *fmt, ...); 18 | 19 | #ifdef CONFIG_TRACE_ERROR 20 | #define trace_error(code) ({ \ 21 | printk("%s:%d: returning error %s\n", __FILE__, __LINE__, #code); \ 22 | code; \ 23 | }) 24 | #else /* !CONFIG_TRACE_ERROR */ 25 | #define trace_error(code) code 26 | #endif /* !CONFIG_TRACE_ERROR */ 27 | 28 | void arch_dbg_write_init(void); 29 | extern void (*arch_dbg_write)(const char *msg); 30 | 31 | extern bool virtual_console; 32 | extern volatile struct jailhouse_virt_console console; 33 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2016 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | unsigned long long __aeabi_llsl(unsigned long long val, unsigned int shift); 16 | unsigned long long __aeabi_llsr(unsigned long long val, unsigned int shift); 17 | 18 | unsigned long long __aeabi_llsl(unsigned long long val, unsigned int shift) 19 | { 20 | u32 lo = (u32)val << shift; 21 | u32 hi = ((u32)(val >> 32) << shift) | ((u32)val >> (32 - shift)); 22 | 23 | return ((unsigned long long)hi << 32) | lo; 24 | } 25 | 26 | unsigned long long __aeabi_llsr(unsigned long long val, unsigned int shift) 27 | { 28 | u32 lo = ((u32)val >> shift) | ((u32)(val >> 32) << (32 - shift)); 29 | u32 hi = (u32)val >> shift; 30 | 31 | return ((unsigned long long)hi << 32) | lo; 32 | } 33 | -------------------------------------------------------------------------------- /scripts/make_release: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Jailhouse, a Linux-based partitioning hypervisor 4 | # 5 | # Copyright (c) Siemens AG, 2014 6 | # 7 | # Authors: 8 | # Jan Kiszka 9 | # 10 | # This work is licensed under the terms of the GNU GPL, version 2. See 11 | # the COPYING file in the top-level directory. 12 | # 13 | 14 | usage() { 15 | echo "usage: $0 name" 16 | exit 1 17 | } 18 | 19 | name=$1 20 | 21 | if [ -z "$name" ]; then 22 | usage 23 | fi 24 | 25 | if [ ! -f VERSION ] || [ ! -d .git ]; then 26 | echo "Must be run from top-level directory" 27 | exit 1 28 | fi 29 | 30 | if [ -n "`git status -s -uno`" ]; then 31 | echo "Working directory is dirty!" 32 | exit 1 33 | fi 34 | 35 | echo -e "Tag commit\n\n `git log -1 --oneline`" 36 | echo -e "\nof branch\n\n `git branch | sed -n 's/^\* //p'`" 37 | echo -ne "\nas $name? (y/N) " 38 | read answer 39 | if [ "$answer" != "y" ]; then 40 | exit 1 41 | fi 42 | 43 | echo $name > VERSION 44 | git commit -sv VERSION -m "Bump version number" 45 | git tag -as $name -m "Release $name" 46 | -------------------------------------------------------------------------------- /hypervisor/uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) OTH Regensburg, 2016 5 | * Copyright (c) Siemens AG, 2020 6 | * 7 | * Authors: 8 | * Ralf Ramsauer 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | struct uart_chip *uart = NULL; 21 | 22 | static void uart_write_char(char c) 23 | { 24 | while (uart->is_busy(uart)) 25 | cpu_relax(); 26 | if (panic_in_progress && panic_cpu != phys_processor_id()) 27 | return; 28 | uart->write_char(uart, c); 29 | } 30 | 31 | void uart_write(const char *msg) 32 | { 33 | char c; 34 | 35 | while (1) { 36 | c = *msg++; 37 | if (!c) 38 | break; 39 | 40 | if (c == '\n') 41 | uart_write_char('\r'); 42 | 43 | uart_write_char(c); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/asm-defines.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Valentine Sinitsyn, 2014 5 | * 6 | * Authors: 7 | * Valentine Sinitsyn 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | void common(void); 19 | 20 | void common(void) 21 | { 22 | OFFSET(PERCPU_LINUX_SP, per_cpu, linux_sp); 23 | BLANK(); 24 | 25 | OFFSET(PERCPU_VMCB_RAX, per_cpu, vmcb.rax); 26 | BLANK(); 27 | 28 | /* GCC evaluates constant expressions involving built-ins 29 | * at compilation time, so this yields computed value. 30 | */ 31 | DEFINE(PERCPU_STACK_END, 32 | __builtin_offsetof(struct per_cpu, stack) + \ 33 | FIELD_SIZEOF(struct per_cpu, stack)); 34 | DEFINE(PERCPU_SIZE_ASM, sizeof(struct per_cpu)); 35 | DEFINE(LOCAL_CPU_BASE_ASM, LOCAL_CPU_BASE); 36 | } 37 | -------------------------------------------------------------------------------- /include/jailhouse/coloring-common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse Cache coloring for ARM64 3 | * 4 | * Copyright (C) 2018 Università di Modena e Reggio Emilia 5 | * 6 | * Authors: 7 | * Luca Miccio 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | #ifndef _JAILHOUSE_COLORING_COMMON_H 13 | #define _JAILHOUSE_COLORING_COMMON_H 14 | #include 15 | /** 16 | * Find all the ranges (i,j) s.t (i<=k<=j and mask[k]=1) in mask 17 | */ 18 | static void ranges_in_mask(bool* mask, int size, int* values) 19 | { 20 | int i = 0, j = 0, k = 0, current_value = 0; 21 | 22 | /* Setup all values to -1 */ 23 | for(i = 0;i < size*2; i++) 24 | values[i] = -1; 25 | for (k = 0; k < size; k++) { 26 | if(mask[k]){ 27 | i = k; 28 | j = i; 29 | while(mask[++j] && j < size); 30 | values[current_value] = i; 31 | values[++current_value] = j-1; 32 | current_value++; 33 | k = j; 34 | } 35 | } 36 | } 37 | 38 | #endif /* _JAILHOUSE_COLORING_COMMON_H */ 39 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/control.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_CONTROL_H 14 | #define _JAILHOUSE_ASM_CONTROL_H 15 | 16 | #define SGI_INJECT 0 17 | #define SGI_EVENT 1 18 | 19 | #ifndef __ASSEMBLY__ 20 | 21 | #include 22 | 23 | void arch_handle_sgi(u32 irqn, unsigned int count_event); 24 | bool arch_handle_phys_irq(u32 irqn, unsigned int count_event); 25 | 26 | union registers* arch_handle_exit(union registers *regs); 27 | 28 | void arch_shutdown_self(struct per_cpu *cpu_data); 29 | 30 | unsigned int arm_cpu_by_mpidr(struct cell *cell, unsigned long mpidr); 31 | 32 | void arm_cpu_reset(unsigned long pc); 33 | void arm_cpu_park(void); 34 | 35 | #endif /* !__ASSEMBLY__ */ 36 | 37 | #endif /* !_JAILHOUSE_ASM_CONTROL_H */ 38 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/arch_gicv3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) 2017 Texas Instruments Incorporated - http://www.ti.com/ 5 | * 6 | * Author: 7 | * Lokesh Vutla 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_ARM64_GIC_V3_H 14 | #define _JAILHOUSE_ASM_ARM64_GIC_V3_H 15 | 16 | #include 17 | 18 | #define ICH_LR0_7_EL2(x) SYSREG_64(4, c12, c12, x) 19 | #define ICH_LR8_15_EL2(x) SYSREG_64(4, c12, c13, x) 20 | 21 | #define ICC_SGI1R_EL1 SYSREG_64(0, c12, c11, 5) 22 | 23 | #define ARM_GIC_READ_LR0_7(n, val) arm_read_sysreg(ICH_LR0_7_EL2(n), val); 24 | #define ARM_GIC_WRITE_LR0_7(n, val) arm_write_sysreg(ICH_LR0_7_EL2(n), val); 25 | 26 | #define ARM_GIC_READ_LR8_15(n, val) arm_read_sysreg(ICH_LR8_15_EL2(n), val); 27 | #define ARM_GIC_WRITE_LR8_15(n, val) \ 28 | arm_write_sysreg(ICH_LR8_15_EL2(n), val); 29 | 30 | #endif /* _JAILHOUSE_ASM_ARM64_GIC_V3_H */ 31 | -------------------------------------------------------------------------------- /scripts/gen_pci_defs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Jailhouse, a Linux-based partitioning hypervisor 4 | # 5 | # Copyright (c) OTH Regensburg, 2019 6 | # 7 | # Authors: 8 | # Ralf Ramsauer 9 | # 10 | # This work is licensed under the terms of the GNU GPL, version 2. See 11 | # the COPYING file in the top-level directory. 12 | 13 | CELL_CONFIG_H=$1 14 | 15 | function find_defines() { 16 | header=$1 17 | prefix=$2 18 | search="#define\s\+${prefix}\(\S*\)\s\+\(\S*\).*" 19 | replace=" '\1'\t: \2," 20 | 21 | grep $prefix $header | sed -e "s/$search/$replace/" 22 | } 23 | 24 | PCI_CAP_IDS=$(find_defines $CELL_CONFIG_H PCI_CAP_ID_) 25 | PCI_EXT_CAP_IDS=$(find_defines $CELL_CONFIG_H PCI_EXT_CAP_ID_) 26 | 27 | cat < 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #ifndef _JAILHOUSE_ASM_AMD_IOMMU_H 16 | #define _JAILHOUSE_ASM_AMD_IOMMU_H 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | #define AMD_IOMMU_PTE_P (1ULL << 0) 24 | #define AMD_IOMMU_PTE_PG_MODE(level) ((level) << 9) 25 | #define AMD_IOMMU_PTE_PG_MODE_MASK BIT_MASK(11, 9) 26 | #define AMD_IOMMU_PTE_IR (1ULL << 61) 27 | #define AMD_IOMMU_PTE_IW (1ULL << 62) 28 | 29 | #define AMD_IOMMU_PAGE_DEFAULT_FLAGS (AMD_IOMMU_PTE_IW | AMD_IOMMU_PTE_IR | \ 30 | AMD_IOMMU_PTE_P) 31 | 32 | u64 amd_iommu_get_memory_region_flags(const struct jailhouse_memory *mem); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/vmx-vmexit.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | /* VMX VM-exit handling */ 17 | .globl vmx_vmexit 18 | vmx_vmexit: 19 | push %rax 20 | push %rcx 21 | push %rdx 22 | push %rbx 23 | sub $8,%rsp /* placeholder for rsp */ 24 | push %rbp 25 | push %rsi 26 | push %rdi 27 | push %r8 28 | push %r9 29 | push %r10 30 | push %r11 31 | push %r12 32 | push %r13 33 | push %r14 34 | push %r15 35 | 36 | mov $LOCAL_CPU_BASE_ASM,%rdi 37 | call vcpu_handle_exit 38 | 39 | pop %r15 40 | pop %r14 41 | pop %r13 42 | pop %r12 43 | pop %r11 44 | pop %r10 45 | pop %r9 46 | pop %r8 47 | pop %rdi 48 | pop %rsi 49 | pop %rbp 50 | add $8,%rsp 51 | pop %rbx 52 | pop %rdx 53 | pop %rcx 54 | pop %rax 55 | 56 | vmresume 57 | 58 | jmp vmx_entry_failure 59 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/iommu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) 2018 Texas Instruments Incorporated - http://www.ti.com 5 | * 6 | * Authors: 7 | * Nikhil Devshatwar 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | unsigned int iommu_count_units(void) 18 | { 19 | unsigned int units = 0; 20 | 21 | while (units < JAILHOUSE_MAX_IOMMU_UNITS && 22 | system_config->platform_info.iommu_units[units].base) 23 | units++; 24 | return units; 25 | } 26 | 27 | int iommu_map_memory_region(struct cell *cell, 28 | const struct jailhouse_memory *mem) 29 | { 30 | return pvu_iommu_map_memory(cell, mem); 31 | } 32 | 33 | int iommu_unmap_memory_region(struct cell *cell, 34 | const struct jailhouse_memory *mem) 35 | { 36 | return pvu_iommu_unmap_memory(cell, mem); 37 | } 38 | 39 | void iommu_config_commit(struct cell *cell) 40 | { 41 | pvu_iommu_config_commit(cell); 42 | } 43 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/iommu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) 2019 Texas Instruments Incorporated - http://www.ti.com 5 | * 6 | * Authors: 7 | * Nikhil Devshatwar 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_IOMMU_H 14 | #define _JAILHOUSE_ASM_IOMMU_H 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #define for_each_stream_id(sid, config, counter) \ 21 | for ((sid) = (jailhouse_cell_stream_ids(config)[0]), (counter) = 0; \ 22 | (counter) < (config)->num_stream_ids; \ 23 | (sid) = (jailhouse_cell_stream_ids(config)[++(counter)])) 24 | 25 | unsigned int iommu_count_units(void); 26 | int iommu_map_memory_region(struct cell *cell, 27 | const struct jailhouse_memory *mem); 28 | int iommu_unmap_memory_region(struct cell *cell, 29 | const struct jailhouse_memory *mem); 30 | void iommu_config_commit(struct cell *cell); 31 | #endif 32 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/iommu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014-2020 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | unsigned int fault_reporting_cpu_id; 17 | 18 | unsigned int iommu_count_units(void) 19 | { 20 | unsigned int units = 0; 21 | 22 | while (units < JAILHOUSE_MAX_IOMMU_UNITS && 23 | system_config->platform_info.iommu_units[units].base) 24 | units++; 25 | return units; 26 | } 27 | 28 | struct public_per_cpu *iommu_select_fault_reporting_cpu(void) 29 | { 30 | /* 31 | * The selection process assumes that at least one bit is set somewhere 32 | * because we don't support configurations where Linux is left with no 33 | * CPUs. 34 | * Save this value globally to avoid multiple reports of the same 35 | * case from different CPUs. 36 | */ 37 | unsigned int fault_reporting_cpu_id = first_cpu(root_cell.cpu_set); 38 | 39 | return public_per_cpu(fault_reporting_cpu_id); 40 | } 41 | -------------------------------------------------------------------------------- /hypervisor/lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | void *memset(void *s, int c, unsigned long n) 17 | { 18 | u8 *p = s; 19 | 20 | while (n-- > 0) 21 | *p++ = c; 22 | return s; 23 | } 24 | 25 | int strcmp(const char *s1, const char *s2) 26 | { 27 | while (*s1 == *s2) { 28 | if (*s1 == '\0') 29 | return 0; 30 | s1++; 31 | s2++; 32 | } 33 | return *(unsigned char *)s1 - *(unsigned char *)s2; 34 | } 35 | 36 | int strncmp(const char *s1, const char *s2, unsigned long n) 37 | { 38 | while (*s1 == *s2 && n--) { 39 | if (*s1 == '\0') 40 | return 0; 41 | s1++; 42 | s2++; 43 | } 44 | return *(unsigned char *)s1 - *(unsigned char *)s2; 45 | } 46 | 47 | void *memcpy(void *dest, const void *src, unsigned long n) 48 | { 49 | const u8 *s = src; 50 | u8 *d = dest; 51 | 52 | while (n-- > 0) 53 | *d++ = *s++; 54 | return dest; 55 | } 56 | -------------------------------------------------------------------------------- /configs/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | -include $(GEN_CONFIG_MK) 14 | 15 | LINUXINCLUDE := -I$(src)/../hypervisor/arch/$(SRCARCH)/include \ 16 | -I$(src)/../hypervisor/include \ 17 | -I$(src)/../include 18 | KBUILD_CFLAGS := -Wextra -D__LINUX_COMPILER_TYPES_H 19 | 20 | ifneq ($(wildcard $(obj)/../include/jailhouse/config.h),) 21 | KBUILD_CFLAGS += -include $(obj)/../include/jailhouse/config.h 22 | endif 23 | 24 | OBJCOPYFLAGS := -O binary 25 | 26 | CONFIGS = $(shell cd $(src); ls $(SRCARCH)/*.c) 27 | 28 | always := $(CONFIGS:.c=.cell) 29 | 30 | targets += $(CONFIGS:.c=.o) $(CONFIGS:.c=.cell) 31 | 32 | DTS = $(shell cd $(src); ls $(SRCARCH)/dts/*.dts 2>/dev/null) 33 | always += $(DTS:.dts=.dtb) 34 | targets += $(DTS:.dts=.dtb) 35 | 36 | # prevent deleting intermediate files which would cause rebuilds 37 | .SECONDARY: $(addprefix $(obj)/,$(CONFIGS:.c=.o)) 38 | 39 | $(obj)/%.cell: $(obj)/%.o 40 | $(call if_changed,objcopy) 41 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/pci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Ivan Kolchin 8 | * Jan Kiszka 9 | * 10 | * This work is licensed under the terms of the GNU GPL, version 2. See 11 | * the COPYING file in the top-level directory. 12 | */ 13 | 14 | #ifndef _JAILHOUSE_ASM_PCI_H 15 | #define _JAILHOUSE_ASM_PCI_H 16 | 17 | #include 18 | #include 19 | 20 | /* --- PCI configuration ports --- */ 21 | #define PCI_REG_ADDR_PORT 0xcf8 22 | #define PCI_REG_DATA_PORT 0xcfc 23 | 24 | /* --- Address register fields --- */ 25 | #define PCI_ADDR_ENABLE (1UL << 31) 26 | #define PCI_ADDR_BDF_SHIFT 8 27 | #define PCI_ADDR_REGNUM_MASK BIT_MASK(7, 2) 28 | 29 | /** 30 | * @ingroup PCI 31 | * @defgroup PCI-X86 x86 32 | * @{ 33 | */ 34 | 35 | int x86_pci_config_handler(u16 port, bool dir_in, unsigned int size); 36 | 37 | struct apic_irq_message 38 | x86_pci_translate_msi(struct pci_device *device, unsigned int vector, 39 | unsigned int legacy_vectors, union x86_msi_vector msi); 40 | 41 | /** @} */ 42 | #endif /* !_JAILHOUSE_ASM_PCI_H */ 43 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/sections.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse AArch64 support 3 | * 4 | * Copyright (C) 2015-2016 Huawei Technologies Duesseldorf GmbH 5 | * Copyright (c) 2016 Siemens AG 6 | * 7 | * Authors: 8 | * Antonios Motakis 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | /* 16 | * We have no memory management during early init; four pages is the minimum we 17 | * can get away with to switch on the MMU with mappings for the hypervisor 18 | * firmware and the UART as well as identity mapping for the trampoline code 19 | * page. 20 | */ 21 | #define ARCH_SECTIONS \ 22 | . = ALIGN(PAGE_SIZE); \ 23 | .bootstrap_page_tables : { \ 24 | bootstrap_pt_l0 = .; \ 25 | . = . + PAGE_SIZE; \ 26 | bootstrap_pt_l1_hyp_uart = .; \ 27 | . = . + PAGE_SIZE; \ 28 | bootstrap_pt_l1_trampoline = .; \ 29 | . = . + PAGE_SIZE; \ 30 | bootstrap_pt_l2_hyp_uart = .; \ 31 | . = . + PAGE_SIZE; \ 32 | } \ 33 | .trampoline : { \ 34 | __trampoline_start = .; \ 35 | *(.trampoline) \ 36 | } 37 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) OTH Regensburg, 2017 5 | * 6 | * Authors: 7 | * Ralf Ramsauer 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | struct uart_chip { 16 | /* must be set by the caller */ 17 | void *virt_base; 18 | struct jailhouse_console *debug_console; 19 | 20 | /* driver selects defaults, if used */ 21 | void (*reg_out)(struct uart_chip *chip, unsigned int reg, u32 value); 22 | u32 (*reg_in)(struct uart_chip *chip, unsigned int reg); 23 | 24 | /* set by the driver */ 25 | void (*init)(struct uart_chip *chip); 26 | bool (*is_busy)(struct uart_chip *chip); 27 | void (*write_char)(struct uart_chip *chip, char c); 28 | 29 | /* Additional driver functions if mode switch requried between 30 | * linux and jailhouse */ 31 | void (*hyp_mode_enter)(struct uart_chip *chip); 32 | void (*hyp_mode_leave)(struct uart_chip *chip); 33 | }; 34 | 35 | void uart_write(const char *msg); 36 | 37 | extern struct uart_chip *uart; 38 | extern struct uart_chip uart_8250_ops; 39 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/bitops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2020 5 | * Copyright (c) ARM Limited, 2014 6 | * 7 | * Authors: 8 | * Jan Kiszka 9 | * Jean-Philippe Brucker 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | static inline __attribute__((always_inline)) int 16 | test_bit(unsigned int nr, const volatile unsigned long *addr) 17 | { 18 | return ((1UL << (nr % BITS_PER_LONG)) & 19 | (addr[nr / BITS_PER_LONG])) != 0; 20 | } 21 | 22 | /* Count leading zeroes */ 23 | static inline unsigned long clz(unsigned long word) 24 | { 25 | unsigned long val; 26 | 27 | asm volatile ("clz %0, %1" : "=r" (val) : "r" (word)); 28 | return val; 29 | } 30 | 31 | /* Returns the position of the least significant 1, MSB=31, LSB=0*/ 32 | static inline unsigned long ffsl(unsigned long word) 33 | { 34 | if (!word) 35 | return 0; 36 | asm volatile ("rbit %0, %0" : "+r" (word)); 37 | return clz(word); 38 | } 39 | 40 | static inline unsigned long ffzl(unsigned long word) 41 | { 42 | return ffsl(~word); 43 | } 44 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * This file is based on linux/arch/x86/include/asm/spinlock.h: 13 | * 14 | * Copyright (c) Linux kernel developers, 2014 15 | */ 16 | 17 | #ifndef _JAILHOUSE_ASM_SPINLOCK_H 18 | #define _JAILHOUSE_ASM_SPINLOCK_H 19 | 20 | #include 21 | 22 | typedef struct { 23 | u16 owner, next; 24 | } spinlock_t; 25 | 26 | static inline void spin_lock(spinlock_t *lock) 27 | { 28 | register spinlock_t inc = { .next = 1 }; 29 | 30 | asm volatile("lock xaddl %0, %1" 31 | : "+r" (inc), "+m" (*lock) 32 | : : "memory", "cc"); 33 | 34 | if (inc.owner != inc.next) 35 | while (lock->owner != inc.next) 36 | cpu_relax(); 37 | 38 | asm volatile("" : : : "memory"); 39 | } 40 | 41 | static inline void spin_unlock(spinlock_t *lock) 42 | { 43 | asm volatile("addw %1, %0" 44 | : "+m" (lock->owner) 45 | : "ri" (1) 46 | : "memory", "cc"); 47 | } 48 | 49 | #endif /* !_JAILHOUSE_ASM_SPINLOCK_H */ 50 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/bitops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2020 5 | * Copyright (c) ARM Limited, 2014 6 | * 7 | * Authors: 8 | * Jan Kiszka 9 | * Jean-Philippe Brucker 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | /* also include from arm-common */ 16 | #include_next 17 | 18 | static inline int atomic_test_and_set_bit(int nr, volatile unsigned long *addr) 19 | { 20 | unsigned long ret, val, test; 21 | 22 | /* word-align */ 23 | addr = (unsigned long *)((u32)addr & ~0x3) + nr / BITS_PER_LONG; 24 | nr %= BITS_PER_LONG; 25 | 26 | /* Load the cacheline in exclusive state */ 27 | asm volatile ( 28 | ".arch_extension mp\n\t" 29 | "pldw %0\n\t" 30 | : "+Qo" (*(volatile unsigned long *)addr)); 31 | do { 32 | asm volatile ( 33 | "ldrex %1, %3\n\t" 34 | "ands %2, %1, %4\n\t" 35 | "it eq\n\t" 36 | "orreq %1, %4\n\t" 37 | "strex %0, %1, %3\n\t" 38 | : "=r" (ret), "=r" (val), "=r" (test), 39 | "+Qo" (*(volatile unsigned long *)addr) 40 | : "r" (1 << nr)); 41 | } while (ret); 42 | 43 | return !!(test); 44 | } 45 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/svm-vmexit.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Valentine Sinitsyn, 2014 5 | * 6 | * Authors: 7 | * Valentine Sinitsyn 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | /* SVM VM entry and handling of VM exit */ 17 | .globl svm_vmentry 18 | svm_vmentry: 19 | vmrun %rax 20 | 21 | /* XXX: GIF is always cleared here */ 22 | push -PERCPU_STACK_END+PERCPU_VMCB_RAX(%rsp) 23 | push %rcx 24 | push %rdx 25 | push %rbx 26 | sub $8,%rsp /* placeholder for rsp */ 27 | push %rbp 28 | push %rsi 29 | push %rdi 30 | push %r8 31 | push %r9 32 | push %r10 33 | push %r11 34 | push %r12 35 | push %r13 36 | push %r14 37 | push %r15 38 | 39 | mov $LOCAL_CPU_BASE_ASM,%rdi 40 | push %rax 41 | call vcpu_handle_exit 42 | pop %rax 43 | 44 | pop %r15 45 | pop %r14 46 | pop %r13 47 | pop %r12 48 | pop %r11 49 | pop %r10 50 | pop %r9 51 | pop %r8 52 | pop %rdi 53 | pop %rsi 54 | pop %rbp 55 | add $8,%rsp 56 | pop %rbx 57 | pop %rdx 58 | pop %rcx 59 | pop -PERCPU_STACK_END+PERCPU_VMCB_RAX(%rsp) 60 | 61 | jmp svm_vmentry 62 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/setup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2017 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | static u32 __attribute__((aligned(PAGE_SIZE))) parking_code[PAGE_SIZE / 4] = { 20 | ARM_PARKING_CODE 21 | }; 22 | 23 | int arm_init_early(void) 24 | { 25 | int err; 26 | 27 | parking_pt.root_paging = cell_paging; 28 | 29 | err = paging_create(&parking_pt, paging_hvirt2phys(parking_code), 30 | PAGE_SIZE, 0, 31 | (PTE_FLAG_VALID | PTE_ACCESS_FLAG | 32 | S2_PTE_ACCESS_RO | S2_PTE_FLAG_NORMAL), 33 | PAGING_COHERENT | PAGING_NO_HUGE); 34 | if (err) 35 | return err; 36 | 37 | return arm_paging_cell_init(&root_cell); 38 | } 39 | 40 | int arm_cpu_init(struct per_cpu *cpu_data) 41 | { 42 | cpu_data->public.mpidr = phys_processor_id(); 43 | 44 | arm_paging_vcpu_init(&root_cell.arch.mm); 45 | 46 | smccc_discover(); 47 | 48 | return irqchip_cpu_init(cpu_data); 49 | } 50 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/i8042.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | int i8042_access_handler(u16 port, bool dir_in, unsigned int size) 22 | { 23 | union registers *guest_regs = &this_cpu_data()->guest_regs; 24 | u8 val; 25 | 26 | if (port == I8042_CMD_REG && this_cell()->arch.pio_i8042_allowed) { 27 | if (size != 1) 28 | goto invalid_access; 29 | if (dir_in) { 30 | guest_regs->rax &= ~BYTE_MASK(1); 31 | guest_regs->rax |= inb(I8042_CMD_REG); 32 | } else { 33 | val = (u8)guest_regs->rax; 34 | if (val == I8042_CMD_WRITE_CTRL_PORT || 35 | (val & I8042_CMD_PULSE_CTRL_PORT) == 36 | I8042_CMD_PULSE_CTRL_PORT) 37 | goto invalid_access; 38 | outb(val, I8042_CMD_REG); 39 | } 40 | return 1; 41 | } 42 | return 0; 43 | 44 | invalid_access: 45 | panic_printk("FATAL: Invalid write to i8042 controller port\n"); 46 | return -1; 47 | } 48 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/smc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (C) 2018 OTH Regensburg 5 | * 6 | * Authors: 7 | * Ralf Ramsauer 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | static inline int smc(unsigned long id) 14 | { 15 | register unsigned long __id asm("r0") = id; 16 | 17 | asm volatile ("smc #0\n\t" 18 | : "=r" (__id) 19 | : "r"(__id) 20 | : "memory", "x1", "x2", "x3"); 21 | 22 | return __id; 23 | } 24 | 25 | static inline int smc_arg1(unsigned long id, unsigned long par1) 26 | { 27 | register unsigned long __id asm("r0") = id; 28 | register unsigned long __par1 asm("r1") = par1; 29 | 30 | asm volatile ("smc #0\n\t" 31 | : "=r" (__id) 32 | : "r"(__id), "r"(__par1) 33 | : "memory", "x2", "x3"); 34 | 35 | return __id; 36 | } 37 | 38 | static inline int smc_arg2(unsigned long id, unsigned long par1, unsigned long par2) 39 | { 40 | register unsigned long __id asm("r0") = id; 41 | register unsigned long __par1 asm("r1") = par1; 42 | register unsigned long __par2 asm("r2") = par2; 43 | 44 | asm volatile ("smc #0\n\t" 45 | : "=r" (__id) 46 | : "r"(__id), "r"(__par1), "r"(__par2) 47 | : "memory", "x3", "x4"); 48 | 49 | return __id; 50 | } 51 | -------------------------------------------------------------------------------- /inmates/demos/x86/smp-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2015 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | #define IPI_VECTOR 40 16 | 17 | static volatile bool done; 18 | static unsigned int main_cpu; 19 | 20 | static void ipi_handler(unsigned int irq) 21 | { 22 | if (irq != IPI_VECTOR) 23 | return; 24 | 25 | printk("Received IPI on %d\n", cpu_id()); 26 | done = true; 27 | } 28 | 29 | static void secondary_main(void) 30 | { 31 | printk("Hello from CPU %d!\n", cpu_id()); 32 | irq_send_ipi(main_cpu, IPI_VECTOR); 33 | } 34 | 35 | void inmate_main(void) 36 | { 37 | unsigned int n; 38 | 39 | main_cpu = cpu_id(); 40 | printk("SMP demo, primary CPU: %d\n", main_cpu); 41 | 42 | printk("Waiting for the rest..."); 43 | smp_wait_for_all_cpus(); 44 | printk("\nFound %d other CPU(s)\n", smp_num_cpus - 1); 45 | 46 | irq_init(ipi_handler); 47 | 48 | asm volatile("sti"); 49 | 50 | for (n = 1; n < smp_num_cpus; n++) { 51 | printk(" Starting CPU %d\n", smp_cpu_ids[n]); 52 | done = false; 53 | smp_start_cpu(smp_cpu_ids[n], secondary_main); 54 | while (!done) 55 | cpu_relax(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/smccc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ 5 | * 6 | * Authors: 7 | * Lokesh Vutla 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #define SMCCC_VERSION 0x80000000 14 | #define SMCCC_ARCH_FEATURES 0x80000001 15 | #define SMCCC_ARCH_WORKAROUND_1 0x80008000 16 | #define SMCCC_ARCH_WORKAROUND_2 0x80007fff 17 | 18 | #define ARM_SMCCC_OWNER_MASK BIT_MASK(29, 24) 19 | #define ARM_SMCCC_OWNER_SHIFT 24 20 | 21 | #define ARM_SMCCC_OWNER_ARCH 0 22 | #define ARM_SMCCC_OWNER_SIP 2 23 | #define ARM_SMCCC_OWNER_STANDARD 4 24 | 25 | #define ARM_SMCCC_CONV_32 0 26 | #define ARM_SMCCC_CONV_64 1 27 | 28 | #define ARM_SMCCC_NOT_SUPPORTED (-1) 29 | #define ARM_SMCCC_SUCCESS 0 30 | 31 | #define ARM_SMCCC_VERSION_1_1 0x10001 32 | 33 | #define SMCCC_GET_OWNER(id) ((id & ARM_SMCCC_OWNER_MASK) >> \ 34 | ARM_SMCCC_OWNER_SHIFT) 35 | 36 | #define SMCCC_IS_CONV_64(function_id) !!(function_id & (1 << 30)) 37 | 38 | #ifndef __ASSEMBLY__ 39 | 40 | struct trap_context; 41 | 42 | void smccc_discover(void); 43 | enum trap_return handle_smc(struct trap_context *ctx); 44 | 45 | #endif /* !__ASSEMBLY__ */ 46 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/bitops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse AArch64 support 3 | * 4 | * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | * 6 | * Authors: 7 | * Claudio Fontana 8 | * Antonios Motakis 9 | * 10 | * This work is licensed under the terms of the GNU GPL, version 2. See 11 | * the COPYING file in the top-level directory. 12 | */ 13 | 14 | #ifndef _JAILHOUSE_ARCH_BITOPS_H 15 | #define _JAILHOUSE_ARCH_BITOPS_H 16 | 17 | /* also include from arm-common */ 18 | #include_next 19 | 20 | static inline int atomic_test_and_set_bit(int nr, volatile unsigned long *addr) 21 | { 22 | u32 ret; 23 | u64 test, tmp; 24 | 25 | /* word-align */ 26 | addr = (unsigned long *)((u64)addr & ~0x7) + nr / BITS_PER_LONG; 27 | nr %= BITS_PER_LONG; 28 | 29 | 30 | /* AARCH64_TODO: using Inner Shareable DMB at the moment, 31 | * revisit when we will deal with shareability domains */ 32 | 33 | do { 34 | asm volatile ( 35 | "ldxr %3, %2\n\t" 36 | "ands %1, %3, %4\n\t" 37 | "b.ne 1f\n\t" 38 | "orr %3, %3, %4\n\t" 39 | "1:\n\t" 40 | "stxr %w0, %3, %2\n\t" 41 | "dmb ish\n\t" 42 | : "=&r" (ret), "=&r" (test), 43 | "+Q" (*(volatile unsigned long *)addr), 44 | "=&r" (tmp) 45 | : "r" (1ul << nr)); 46 | } while (ret); 47 | return !!(test); 48 | } 49 | 50 | #endif /* _JAILHOUSE_ARCH_BITOPS_H */ 51 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2018 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_TYPES_H 14 | #define _JAILHOUSE_TYPES_H 15 | 16 | #include 17 | 18 | #define NULL ((void *)0) 19 | 20 | #ifndef __ASSEMBLY__ 21 | 22 | typedef enum { true = 1, false = 0 } bool; 23 | 24 | /** Describes a CPU set. */ 25 | struct cpu_set { 26 | /** Maximum CPU ID expressible with this set. */ 27 | unsigned long max_cpu_id; 28 | /** Bitmap of CPUs in the set. 29 | * @note Typically, the bitmap is extended by embedding this structure 30 | * into a larger buffer. */ 31 | unsigned long bitmap[1]; 32 | }; 33 | 34 | typedef signed char s8; 35 | typedef unsigned char u8; 36 | 37 | typedef signed short s16; 38 | typedef unsigned short u16; 39 | 40 | typedef signed int s32; 41 | typedef unsigned int u32; 42 | 43 | typedef signed long long s64; 44 | typedef unsigned long long u64; 45 | 46 | typedef s8 __s8; 47 | typedef u8 __u8; 48 | 49 | typedef s16 __s16; 50 | typedef u16 __u16; 51 | 52 | typedef s32 __s32; 53 | typedef u32 __u32; 54 | 55 | typedef s64 __s64; 56 | typedef u64 __u64; 57 | 58 | #endif /* !__ASSEMBLY__ */ 59 | 60 | #endif /* !_JAILHOUSE_JAILHOUSE_TYPES_H */ 61 | -------------------------------------------------------------------------------- /ci/coverity-scan-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Jailhouse, a Linux-based partitioning hypervisor 4 | # 5 | # Copyright (c) Siemens AG, 2015 6 | # 7 | # Authors: 8 | # Jan Kiszka 9 | # 10 | # This work is licensed under the terms of the GNU GPL, version 2. See 11 | # the COPYING file in the top-level directory. 12 | # 13 | 14 | curl -s https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh \ 15 | -o ci/travisci_build_coverity_scan.sh.orig 16 | 17 | # Patch the line that starts the build. 18 | # We need to control this step via our build script. 19 | sed 's/^COVERITY_UNSUPPORTED=1 cov-build --dir.*/ci\/build-all-configs.sh --cov \$RESULTS_DIR \$COV_BUILD_OPTIONS/' \ 20 | ci/travisci_build_coverity_scan.sh.orig > ci/travisci_build_coverity_scan.sh.step1 21 | 22 | # Path the branch name into the description. 23 | sed 's/^ --form description=.*/ --form description="Travis CI build (branch: \$TRAVIS_BRANCH)" \\/' \ 24 | ci/travisci_build_coverity_scan.sh.step1 > ci/travisci_build_coverity_scan.sh 25 | 26 | # Check if the patch applied, bail out if not. 27 | if diff -q ci/travisci_build_coverity_scan.sh.orig \ 28 | ci/travisci_build_coverity_scan.sh.step1 > /dev/null || \ 29 | diff -q ci/travisci_build_coverity_scan.sh.step1 \ 30 | ci/travisci_build_coverity_scan.sh > /dev/null; then 31 | echo "Unable to patch Coverity script!" 32 | exit 1 33 | fi 34 | 35 | # Run the patched scanner script. 36 | . ci/travisci_build_coverity_scan.sh 37 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/bitops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2020 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_BITOPS_H 14 | #define _JAILHOUSE_BITOPS_H 15 | 16 | #include 17 | #include 18 | 19 | #define FIELD_PREP(mask, val) \ 20 | (((u64)(val) << (__builtin_ffsl((mask)) - 1)) & (mask)) 21 | #define FIELD_GET(mask, reg) \ 22 | (((reg) & (mask)) >> (__builtin_ffsl((mask)) - 1)) 23 | #define FIELD_CLEAR(mask, reg) \ 24 | ((reg) & (~(mask))) 25 | 26 | #define BITS_PER_LONG 64 27 | #define UL(x) ((unsigned long)x) 28 | #define BIT(nr) (UL(1) << (nr)) 29 | #define GENMASK(h, l) \ 30 | (((~UL(0)) - (UL(1) << (l)) + 1) & \ 31 | (~UL(0) >> (BITS_PER_LONG - 1 - (h)))) 32 | 33 | #define __bf_shf(x) (__builtin_ffsll(x) - 1) 34 | 35 | static inline __attribute__((always_inline)) void 36 | clear_bit(unsigned int nr, volatile unsigned long *addr) 37 | { 38 | addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG)); 39 | } 40 | 41 | static inline __attribute__((always_inline)) void 42 | set_bit(unsigned int nr, volatile unsigned long *addr) 43 | { 44 | addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG); 45 | } 46 | 47 | #endif /* !_JAILHOUSE_BITOPS_H */ 48 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014-2018 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * Partly derived from Linux kernel code. 13 | */ 14 | 15 | /* 16 | * We need guards around ARRAY_SIZE as there is a duplicate definition in 17 | * jailhouse/cell-config.h due to header license incompatibility. Once 18 | * ARRAY_SIZE is replaced in cell-config.h, this guard can be removed. 19 | */ 20 | #ifndef ARRAY_SIZE 21 | #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) 22 | #endif 23 | 24 | /* sizeof() for a structure/union field */ 25 | #define FIELD_SIZEOF(type, fld) (sizeof(((type *)0)->fld)) 26 | 27 | /* create 64-bit mask with bytes 0 to size-1 set to 0xff */ 28 | #define BYTE_MASK(size) (0xffffffffffffffffULL >> ((8 - (size)) * 8)) 29 | 30 | /* create 64-bit mask with all bits in [last:first] set */ 31 | #define BIT_MASK(last, first) \ 32 | ((0xffffffffffffffffULL >> (64 - ((last) + 1 - (first)))) << (first)) 33 | 34 | /* extract the field value at [last:first] from an input of up to 64 bits */ 35 | #define GET_FIELD(value, last, first) \ 36 | (((value) & BIT_MASK((last), (first))) >> (first)) 37 | 38 | #define MAX(a, b) ((a) >= (b) ? (a) : (b)) 39 | #define MIN(a, b) ((a) <= (b) ? (a) : (b)) 40 | -------------------------------------------------------------------------------- /Documentation/hypervisor-configuration.md: -------------------------------------------------------------------------------- 1 | Hypervisor Configuration 2 | ======================== 3 | 4 | Jailhouse supports various static compile-time configuration 5 | parameters, such as platform specific settings and debugging options. 6 | Those settings can optionally be defined in 7 | 'include/jailhouse/config.h'. 8 | Every configuration option should be defined to "1" or not be in the file at 9 | all. Defining any other value can cause unexpected behaviour. 10 | 11 | Available configuration options 12 | ------------------------------- 13 | 14 | General configuration parameters 15 | 16 | /* Print error sources with filename and line number to debug console */ 17 | #define CONFIG_TRACE_ERROR 1 18 | 19 | /* 20 | * Set instruction pointer to 0 if cell CPU has caused an access violation. 21 | * Linux inmates will dump a stack trace in this case. 22 | */ 23 | #define CONFIG_CRASH_CELL_ON_PANIC 1 24 | 25 | /* Enable code coverage data collection (see Documentation/gcov.txt) */ 26 | #define CONFIG_JAILHOUSE_GCOV 1 27 | 28 | /* 29 | * Link inmates against a custom base address. Only supported on ARM 30 | * architectures. If this parameter is defined, inmates must be loaded to 31 | * the appropriate location. 32 | */ 33 | #define CONFIG_INMATE_BASE 0x90000000 34 | 35 | /* 36 | * Only available on x86. This debugging option that needs to be activated 37 | * when running mmio-access tests. 38 | */ 39 | #define CONFIG_TEST_DEVICE 1 40 | -------------------------------------------------------------------------------- /hypervisor/hypervisor.lds.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2017 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | SECTIONS 19 | { 20 | . = JAILHOUSE_BASE; 21 | .header : { *(.header) } 22 | 23 | . = ALIGN(16); 24 | .text : { 25 | __text_start = .; 26 | *(.text) 27 | } 28 | 29 | . = ALIGN(16); 30 | .rodata : { *(.rodata) } 31 | 32 | . = ALIGN(16); 33 | .data : { *(.data) } 34 | 35 | . = ALIGN(8); 36 | .init_array : { 37 | __init_array_start = .; 38 | *(SORT(.init_array.*)) *(.init_array) 39 | __init_array_end = .; 40 | } 41 | 42 | .units : { 43 | __unit_array_start = .; 44 | *(.units); 45 | __unit_array_end = .; 46 | } 47 | 48 | ARCH_SECTIONS 49 | 50 | /* The console section shall only contain the hypervisor console. This 51 | * section and the next section must be aligned to PAGE_SIZE, as we 52 | * will map the console section, and only that section, as a whole page 53 | * to the root cell. */ 54 | 55 | . = ALIGN(PAGE_SIZE); 56 | .console : { *(.console) } 57 | 58 | . = ALIGN(PAGE_SIZE); 59 | .bss : { *(.bss) } 60 | 61 | . = ALIGN(PAGE_SIZE); 62 | __page_pool = .; 63 | 64 | .eh_frame : { *(.eh_frame*) } 65 | } 66 | -------------------------------------------------------------------------------- /pyjailhouse/extendedenum.py: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) OTH Regensburg, 2019 5 | # 6 | # Authors: 7 | # Ralf Ramsauer 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | 12 | # Python 2 and 3 have different ways of handling metaclasses. This decorator 13 | # is a support layer for both and can be removed once Python 2 is no longer 14 | # supported. 15 | def with_metaclass(meta): 16 | def decorator(cls): 17 | body = vars(cls).copy() 18 | body.pop('__dict__', None) 19 | body.pop('__weakref__', None) 20 | return meta(cls.__name__, cls.__bases__, body) 21 | return decorator 22 | 23 | 24 | class ExtendedEnumMeta(type): 25 | def __getattr__(cls, key): 26 | return cls(cls._ids[key]) 27 | 28 | 29 | @with_metaclass(ExtendedEnumMeta) 30 | class ExtendedEnum: 31 | def __init__(self, value): 32 | self.value = value 33 | 34 | def __str__(self): 35 | for key, value in self._ids.items(): 36 | if value == self.value: 37 | return '%s_%s' % (self.__class__.__name__, key) 38 | 39 | return '0x%x' % self.value 40 | 41 | def __eq__(self, other): 42 | if isinstance(other, self.__class__): 43 | return self.value == other.value 44 | elif isinstance(other, int): 45 | return self.value == other 46 | return False 47 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/Kbuild: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013-2017 5 | # Copyright (c) Valentine Sinitsyn, 2014 6 | # 7 | # Authors: 8 | # Jan Kiszka 9 | # Valentine Sinitsyn 10 | # 11 | # This work is licensed under the terms of the GNU GPL, version 2. See 12 | # the COPYING file in the top-level directory. 13 | # 14 | 15 | -include $(GEN_CONFIG_MK) 16 | 17 | ccflags-$(CONFIG_JAILHOUSE_GCOV) += -fprofile-arcs -ftest-coverage 18 | 19 | always := lib-amd.a lib-intel.a 20 | 21 | common-objs-y := apic.o dbg-write.o entry.o setup.o control.o mmio.o iommu.o \ 22 | paging.o pci.o i8042.o vcpu.o efifb.o ivshmem.o 23 | 24 | CFLAGS_efifb.o := -I$(src) 25 | 26 | $(obj)/efifb.o: $(src)/altc-8x16 27 | 28 | # units initialization order as defined by linking order: 29 | # iommu, ioapic, [test-device], [cat], 30 | 31 | common-objs-y += ioapic.o 32 | 33 | common-objs-$(CONFIG_TEST_DEVICE) += test-device.o 34 | 35 | amd-objs := svm.o amd_iommu.o svm-vmexit.o $(common-objs-y) 36 | intel-objs := vmx.o vtd.o vmx-vmexit.o $(common-objs-y) cat.o 37 | 38 | targets += $(amd-objs) $(intel-objs) 39 | 40 | quiet_cmd_link_archive = AR $@ 41 | cmd_link_archive = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $^ 42 | 43 | $(obj)/lib-amd.a: $(addprefix $(obj)/,$(amd-objs)) 44 | $(call if_changed,link_archive) 45 | 46 | $(obj)/lib-intel.a: $(addprefix $(obj)/,$(intel-objs)) 47 | $(call if_changed,link_archive) 48 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/include/asm/processor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse AArch64 support 3 | * 4 | * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | * 6 | * Authors: 7 | * Antonios Motakis 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_PROCESSOR_H 14 | #define _JAILHOUSE_ASM_PROCESSOR_H 15 | 16 | #include 17 | #include 18 | 19 | #define NUM_USR_REGS 31 20 | 21 | #ifndef __ASSEMBLY__ 22 | 23 | union registers { 24 | struct { 25 | /* 26 | * We have an odd number of registers, and the stack needs to 27 | * be aligned after pushing all registers. Add 64 bit padding 28 | * at the beginning. 29 | */ 30 | unsigned long __padding; 31 | unsigned long usr[NUM_USR_REGS]; 32 | }; 33 | }; 34 | 35 | #define ARM_PARKING_CODE \ 36 | 0xd503207f, /* 1: wfi */ \ 37 | 0x17ffffff, /* b 1b */ 38 | 39 | #define dmb(domain) asm volatile("dmb " #domain "\n" : : : "memory") 40 | #define dsb(domain) asm volatile("dsb " #domain "\n" : : : "memory") 41 | #define isb() asm volatile("isb\n") 42 | 43 | static inline void cpu_relax(void) 44 | { 45 | asm volatile("" : : : "memory"); 46 | } 47 | 48 | static inline void memory_barrier(void) 49 | { 50 | dmb(ish); 51 | } 52 | 53 | static inline void memory_load_barrier(void) 54 | { 55 | dmb(ish); 56 | } 57 | 58 | #endif /* !__ASSEMBLY__ */ 59 | 60 | #endif /* !_JAILHOUSE_ASM_PROCESSOR_H */ 61 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/paging.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright 2018 NXP 5 | * 6 | * Authors: 7 | * Peng Fan 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /** 18 | * Return the physical address bits. 19 | * 20 | * In arch_paging_init this value will be kept in cpu_parange 21 | * for later reference 22 | * 23 | * @return The physical address bits. 24 | */ 25 | unsigned int get_cpu_parange(void) 26 | { 27 | /* Larger than any possible value */ 28 | unsigned int parange = 0x10; 29 | unsigned int cpu; 30 | 31 | /* 32 | * early_init calls paging_init, which will indirectly call 33 | * get_cpu_parange, prior to cell_init, we cannot use 34 | * for_each_cpu yet. So we need to iterate over the configuration 35 | * of the root cell. 36 | */ 37 | for (cpu = 0; cpu < system_config->root_cell.cpu_set_size * 8; cpu++) 38 | if (cpu_id_valid(cpu) && 39 | (per_cpu(cpu)->id_aa64mmfr0 & 0xf) < parange) 40 | parange = per_cpu(cpu)->id_aa64mmfr0 & 0xf; 41 | 42 | switch (parange) { 43 | case PARANGE_32B: 44 | return 32; 45 | case PARANGE_36B: 46 | return 36; 47 | case PARANGE_40B: 48 | return 40; 49 | case PARANGE_42B: 50 | return 42; 51 | case PARANGE_44B: 52 | return 44; 53 | case PARANGE_48B: 54 | return 48; 55 | default: 56 | return 0; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /inmates/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | -include $(GEN_CONFIG_MK) 14 | 15 | INMATES_LIB = $(src)/lib/$(SRCARCH) 16 | export INMATES_LIB 17 | 18 | INCLUDES := -I$(INMATES_LIB) \ 19 | -I$(src)/../include/arch/$(SRCARCH) \ 20 | -I$(src)/lib/include \ 21 | -I$(src)/../include 22 | 23 | ifeq ($(subst arm64,arm,$(SRCARCH)),arm) 24 | INCLUDES += -I$(src)/../hypervisor/arch/arm-common/include 25 | endif 26 | 27 | LINUXINCLUDE := $(INCLUDES) 28 | KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE 29 | KBUILD_CFLAGS := -g -Os -Wall -Wstrict-prototypes -Wtype-limits \ 30 | -Wmissing-declarations -Wmissing-prototypes \ 31 | -fno-strict-aliasing -fomit-frame-pointer -fno-pic \ 32 | -fno-common -fno-stack-protector -ffreestanding \ 33 | -ffunction-sections \ 34 | -D__LINUX_COMPILER_TYPES_H 35 | ifneq ($(wildcard $(INC_CONFIG_H)),) 36 | KBUILD_CFLAGS += -include $(INC_CONFIG_H) 37 | endif 38 | 39 | OBJCOPYFLAGS := -O binary 40 | # prior to 4.19 41 | LDFLAGS += --gc-sections -T 42 | # since 4.19 43 | KBUILD_LDFLAGS += --gc-sections -T 44 | 45 | subdir-y := lib/$(SRCARCH) demos/$(SRCARCH) tests/$(SRCARCH) tools/$(SRCARCH) 46 | 47 | # demos, tests and tools depend on the library 48 | $(obj)/demos/$(SRCARCH) $(obj)/tests/$(SRCARCH) $(obj)/tools/$(SRCARCH): \ 49 | $(obj)/lib/$(SRCARCH) 50 | -------------------------------------------------------------------------------- /Documentation/glossary.txt: -------------------------------------------------------------------------------- 1 | Glossary 2 | ======== 3 | 4 | Hypervisor 5 | ---------- 6 | System management software that runs at a higher privileged level than any 7 | operating system or application software. It furthermore defines if software 8 | at lower privilege levels has direct access to resources, if access should be 9 | denied or trapped and the hypervisor code invoked on such events. 10 | 11 | Hypervisor Mode 12 | --------------- 13 | Execution mode of a CPU while executing hypervisor code. 14 | 15 | Guest Mode 16 | ---------- 17 | Execution mode of a CPU while executing an operating system or application 18 | software in an isolated environment under the control of the hypervisor. 19 | 20 | Cell 21 | ---- 22 | Protection domain for an operating systems with its application software in 23 | the context of Jailhouse. A cell is granted exclusive or intercepted and 24 | moderated access to system resources like CPUs, RAM or I/O devices. 25 | 26 | Root Cell 27 | --------- 28 | The cell that contains the Linux system which originally started Jailhouse. 29 | The root cell cannot be destroyed, thus exists as long as Jailhouse is active. 30 | 31 | Non-Root Cell 32 | ------------- 33 | Any cell started after the root cell under the control of Jailhouse. There can 34 | be as many non-root cells as required resources are available, Non-root cells 35 | can be destroyed under certain conditions while Jailhouse is running. 36 | 37 | Sysfs 38 | ----- 39 | Linux filesystem that provides a means to export kernel data structures, their 40 | attributes, and the linkages between them to userspace. 41 | -------------------------------------------------------------------------------- /inmates/tools/arm64/linux-loader.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse AArch64 support 3 | * 4 | * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | * 6 | * Authors: 7 | * Dmitry Voytik 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | void inmate_main(void) 17 | { 18 | unsigned long dtb, sctlr; 19 | void (*entry)(u64 dtb, u64 x1, u64 x2, u64 x3); 20 | 21 | entry = (void *)cmdline_parse_int("kernel", 0); 22 | dtb = cmdline_parse_int("dtb", 0); 23 | 24 | /* 25 | * Linux wants the MMU to be disabled 26 | * As we didn't write anything relevant to the caches so far, we can 27 | * get away without flushing. 28 | */ 29 | arm_read_sysreg(SCTLR_EL1, sctlr); 30 | sctlr &= ~SCTLR_EL1_M; 31 | 32 | /* 33 | * This is a pendant for 34 | * arm_write_sysreg(SCTLR_EL1, sctlr); 35 | * instruction_barrier(); 36 | * entry(dtb, 0, 0, 0); 37 | * 38 | * After disabling the MMU, we must not touch the stack because we don't 39 | * flush+inval dcaches, and the compiler might use the stack between 40 | * calling entry. Assembly ensures that everything relevant is kept in 41 | * registers. 42 | */ 43 | asm volatile( 44 | "mov x0, %0\n\t" 45 | "mov x1, #0\n\t" 46 | "mov x2, #0\n\t" 47 | "mov x3, #0\n\t" 48 | "msr sctlr_el1, %1\n\t" 49 | "isb\n\t" 50 | "br %2" /* entry(dtb, 0, 0, 0) */ 51 | : : "r" (dtb), "r" (sctlr), "r" (entry) 52 | : "x0", "x1", "x2", "x3"); 53 | } 54 | -------------------------------------------------------------------------------- /ci/build-all-configs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Jailhouse, a Linux-based partitioning hypervisor 4 | # 5 | # Copyright (c) Siemens AG, 2015, 2016 6 | # 7 | # Authors: 8 | # Jan Kiszka 9 | # 10 | # This work is licensed under the terms of the GNU GPL, version 2. See 11 | # the COPYING file in the top-level directory. 12 | # 13 | 14 | set -e 15 | 16 | CONFIGS="x86 banana-pi amd-seattle" 17 | 18 | # only build a specific config if the branch selects it 19 | if [ ${TRAVIS_BRANCH#coverity_scan-} != ${TRAVIS_BRANCH} ]; then 20 | CONFIGS=${TRAVIS_BRANCH#coverity_scan-} 21 | fi 22 | 23 | PREFIX= 24 | if [ "$1" == "--cov" ]; then 25 | export COVERITY_UNSUPPORTED=1 26 | PREFIX="cov-build --append-log --dir $2 $3" 27 | fi 28 | 29 | for CONFIG in $CONFIGS; do 30 | echo 31 | echo "*** Building configuration $CONFIG ***" 32 | 33 | cp ci/jailhouse-config.h include/jailhouse/config.h 34 | 35 | case $CONFIG in 36 | x86) 37 | ARCH=x86_64 38 | CROSS_COMPILE= 39 | ;; 40 | amd-seattle) 41 | ARCH=arm64 42 | CROSS_COMPILE=aarch64-linux-gnu- 43 | ;; 44 | *) 45 | ARCH=arm 46 | CROSS_COMPILE=arm-linux-gnueabihf- 47 | ;; 48 | esac 49 | 50 | $PREFIX make KDIR=ci/linux/build-$CONFIG ARCH=$ARCH \ 51 | CROSS_COMPILE=$CROSS_COMPILE -j $((2*`nproc`)) 52 | 53 | # Keep the clean run out of sight for cov-build so that results are 54 | # accumulated as far as possible. Multiple compilations of the same 55 | # file will still leave only the last run in the results. 56 | make KDIR=ci/linux/build-$CONFIG ARCH=$ARCH \ 57 | CROSS_COMPILE=$CROSS_COMPILE clean 58 | done 59 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/dbg-write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013-2016 5 | * Copyright (c) OTH Regensburg, 2017 6 | * 7 | * Authors: 8 | * Jan Kiszka 9 | * Ralf Ramsauer 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | static void reg_out_pio(struct uart_chip *chip, unsigned int reg, u32 value) 22 | { 23 | outb(value, (u16)(unsigned long long)chip->virt_base + reg); 24 | } 25 | 26 | static u32 reg_in_pio(struct uart_chip *chip, unsigned int reg) 27 | { 28 | return inb((u16)(unsigned long long)chip->virt_base + reg); 29 | } 30 | 31 | void arch_dbg_write_init(void) 32 | { 33 | u32 dbg_type = system_config->debug_console.type; 34 | 35 | if (dbg_type == JAILHOUSE_CON_TYPE_8250) { 36 | uart = &uart_8250_ops; 37 | 38 | uart->debug_console = &system_config->debug_console; 39 | if (CON_IS_MMIO(system_config->debug_console.flags)) { 40 | uart->virt_base = hypervisor_header.debug_console_base; 41 | } else { 42 | uart->virt_base = 43 | (void *)system_config->debug_console.address; 44 | uart->reg_out = reg_out_pio; 45 | uart->reg_in = reg_in_pio; 46 | } 47 | uart->init(uart); 48 | arch_dbg_write = uart_write; 49 | } else if (dbg_type == JAILHOUSE_CON_TYPE_EFIFB) { 50 | efifb_init(); 51 | arch_dbg_write = efifb_write; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | /** 16 | * @ingroup IO 17 | * @defgroup IO-X86 x86 18 | * @{ 19 | */ 20 | 21 | /** 22 | * Read 8 (b), 16(w) or 32-bit (l) value from a port. 23 | * @param port Port number. 24 | * 25 | * @return Read value. 26 | * @{ 27 | */ 28 | static inline u8 inb(u16 port) 29 | { 30 | u8 v; 31 | 32 | asm volatile("inb %1,%0" : "=a" (v) : "dN" (port)); 33 | return v; 34 | } 35 | 36 | static inline u16 inw(u16 port) 37 | { 38 | u16 v; 39 | 40 | asm volatile("inw %w1,%0" : "=a" (v) : "Nd" (port)); 41 | return v; 42 | } 43 | 44 | static inline u32 inl(u16 port) 45 | { 46 | u32 v; 47 | 48 | asm volatile("inl %1,%0" : "=a" (v) : "dN" (port)); 49 | return v; 50 | } 51 | /** @} */ 52 | 53 | /** 54 | * Write 8 (b), 16(w) or 32-bit (l) value to a port. 55 | * @param value Value to write 56 | * @param port Port number. 57 | * @{ 58 | */ 59 | static inline void outb(u8 value, u16 port) 60 | { 61 | asm volatile("outb %0,%1" : : "a" (value), "dN" (port)); 62 | } 63 | 64 | static inline void outw(u16 value, u16 port) 65 | { 66 | asm volatile("outw %w0,%w1" : : "a" (value), "Nd" (port)); 67 | } 68 | 69 | static inline void outl(u32 value, u16 port) 70 | { 71 | asm volatile("outl %0,%1" : : "a" (value), "Nd" (port)); 72 | } 73 | /** @} */ 74 | 75 | /** @} */ 76 | -------------------------------------------------------------------------------- /hypervisor/gcov.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2017 5 | * 6 | * Authors: 7 | * Henning Schild 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | #include 13 | #include 14 | 15 | extern unsigned long __init_array_start[], __init_array_end[]; 16 | 17 | /* the actual data structure is bigger but we just need to know the version 18 | * independent beginning to link the elements to a list */ 19 | struct gcov_min_info { 20 | unsigned int version; 21 | struct gcov_min_info *next; 22 | }; 23 | 24 | void gcov_init(void) { 25 | unsigned long *iarray = __init_array_start; 26 | unsigned long *iarray_end = __init_array_end; 27 | void (*__init_func)(void); 28 | 29 | while (iarray < iarray_end) { 30 | __init_func = (void(*)(void))iarray[0]; 31 | iarray++; 32 | __init_func(); 33 | } 34 | } 35 | 36 | void __gcov_init(struct gcov_min_info *info); 37 | void __gcov_merge_add(void *counters, unsigned int n_counters); 38 | void __gcov_exit(void); 39 | 40 | /* just link them all together and leave the head in the header 41 | * where a processing tool can find it */ 42 | void __gcov_init(struct gcov_min_info *info) 43 | { 44 | info->next = (struct gcov_min_info *)hypervisor_header.gcov_info_head; 45 | hypervisor_header.gcov_info_head = info; 46 | } 47 | 48 | /* Satisfy the linker, never called */ 49 | void __gcov_merge_add(void *counters, unsigned int n_counters) 50 | { 51 | } 52 | 53 | void __gcov_exit(void) 54 | { 55 | } 56 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/dbg-write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * Copyright (c) OTH Regensburg, 2016 6 | * 7 | * Authors: 8 | * Jean-Philippe Brucker 9 | * Ralf Ramsauer 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void arch_dbg_write_init(void) 21 | { 22 | unsigned char con_type = system_config->debug_console.type; 23 | 24 | if (!CON_IS_MMIO(system_config->debug_console.flags)) 25 | return; 26 | 27 | if (con_type == JAILHOUSE_CON_TYPE_PL011) 28 | uart = &uart_pl011_ops; 29 | else if (con_type == JAILHOUSE_CON_TYPE_8250) 30 | uart = &uart_8250_ops; 31 | else if (con_type == JAILHOUSE_CON_TYPE_XUARTPS) 32 | uart = &uart_xuartps_ops; 33 | else if (con_type == JAILHOUSE_CON_TYPE_MVEBU) 34 | uart = &uart_mvebu_ops; 35 | else if (con_type == JAILHOUSE_CON_TYPE_HSCIF) 36 | uart = &uart_hscif_ops; 37 | else if (con_type == JAILHOUSE_CON_TYPE_SCIFA) 38 | uart = &uart_scifa_ops; 39 | else if (con_type == JAILHOUSE_CON_TYPE_IMX) 40 | uart = &uart_imx_ops; 41 | else if (con_type == JAILHOUSE_CON_TYPE_S32) 42 | uart = &uart_s32_ops; 43 | 44 | if (uart) { 45 | uart->debug_console = &system_config->debug_console; 46 | uart->virt_base = hypervisor_header.debug_console_base; 47 | uart->init(uart); 48 | arch_dbg_write = uart_write; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /inmates/tools/arm/linux-loader.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse ARM support 3 | * 4 | * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | * Copyright (c) Siemens AG, 2016 6 | * 7 | * Authors: 8 | * Dmitry Voytik 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | void inmate_main(void) 19 | { 20 | void register (*entry)(unsigned long, unsigned long, unsigned long); 21 | unsigned long register dtb, sctlr; 22 | 23 | entry = (void *)(unsigned long)cmdline_parse_int("kernel", 0); 24 | dtb = cmdline_parse_int("dtb", 0); 25 | 26 | /* 27 | * Linux wants the MMU and D-caches to be disabled. 28 | * As we didn't write anything relevant to the caches so far, we can 29 | * get away without flushing. 30 | */ 31 | arm_read_sysreg(SCTLR, sctlr); 32 | sctlr &= ~(SCTLR_C | SCTLR_M); 33 | 34 | /* 35 | * This is a pendant for 36 | * arm_write_sysreg(SCTLR, sctlr); 37 | * instruction_barrier(); 38 | * entry(0, -1, dtb); 39 | * 40 | * After disabling the MMU, we must not touch the stack because we don't 41 | * flush+inval dcaches, and the compiler might use the stack between 42 | * calling entry. Assembly ensures that everything relevant is kept in 43 | * registers. 44 | */ 45 | asm volatile( 46 | "mov r0, #0\n\t" 47 | "mov r1, #-1\n\t" 48 | "mov r2, %0\n\t" 49 | "mcr p15, 0, %1, c1, c0, 0\n\t" 50 | "isb\n\t" 51 | "bx %2\n\t" /* entry(0, -1, dtb) */ 52 | : : "r" (dtb), "r" (sctlr), "r" (entry) : "r0", "r1", "r2"); 53 | } 54 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/arch_gicv3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) 2017 Texas Instruments Incorporated - http://www.ti.com/ 5 | * 6 | * Author: 7 | * Lokesh Vutla 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_ARM_GIC_V3_H 14 | #define _JAILHOUSE_ASM_ARM_GIC_V3_H 15 | 16 | #include 17 | 18 | #define ICH_LR0_7(x) SYSREG_32(4, c12, c12, x) 19 | #define ICH_LR8_15(x) SYSREG_32(4, c12, c13, x) 20 | #define ICH_LRC0_7(x) SYSREG_32(4, c12, c14, x) 21 | #define ICH_LRC8_15(x) SYSREG_32(4, c12, c15, x) 22 | 23 | #define ICC_SGI1R_EL1 SYSREG_64(0, c12) 24 | 25 | #define ARM_GIC_READ_LR0_7(n, val) do { \ 26 | u32 lr##n, lrc##n; \ 27 | \ 28 | arm_read_sysreg(ICH_LR0_7(n), lr##n); \ 29 | arm_read_sysreg(ICH_LRC0_7(n), lrc##n); \ 30 | \ 31 | val = ((u64)lrc##n << 32) | lr##n; \ 32 | } while (0); 33 | 34 | #define ARM_GIC_WRITE_LR0_7(n, val) do { \ 35 | arm_write_sysreg(ICH_LR0_7(n), (u32)val); \ 36 | arm_write_sysreg(ICH_LRC0_7(n), val >> 32); \ 37 | } while (0); 38 | 39 | #define ARM_GIC_READ_LR8_15(n, val) do { \ 40 | u32 lr_##n, lrc_##n; \ 41 | \ 42 | arm_read_sysreg(ICH_LR8_15(n), lr_##n); \ 43 | arm_read_sysreg(ICH_LRC8_15(n), lrc_##n); \ 44 | \ 45 | val = ((u64)lrc_##n << 32) | lr_##n; \ 46 | } while (0); 47 | 48 | #define ARM_GIC_WRITE_LR8_15(n, val) do { \ 49 | arm_write_sysreg(ICH_LR8_15(n), (u32)val); \ 50 | arm_write_sysreg(ICH_LRC8_15(n), val >> 32); \ 51 | } while (0); 52 | 53 | #endif /* _JAILHOUSE_ASM_ARM_GIC_V3_H */ 54 | -------------------------------------------------------------------------------- /pyjailhouse/cell.py: -------------------------------------------------------------------------------- 1 | 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2015-2016 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | 12 | import ctypes 13 | import errno 14 | import fcntl 15 | import struct 16 | 17 | 18 | class JailhouseCell: 19 | JAILHOUSE_CELL_CREATE = 0x40100002 20 | JAILHOUSE_CELL_LOAD = 0x40300003 21 | JAILHOUSE_CELL_START = 0x40280004 22 | 23 | JAILHOUSE_CELL_ID_UNUSED = -1 24 | 25 | def __init__(self, config): 26 | self.name = config.name.encode() 27 | 28 | self.dev = open('/dev/jailhouse') 29 | 30 | cbuf = ctypes.create_string_buffer(config.data) 31 | create = struct.pack('QI4x', ctypes.addressof(cbuf), len(config.data)) 32 | try: 33 | fcntl.ioctl(self.dev, JailhouseCell.JAILHOUSE_CELL_CREATE, create) 34 | except IOError as e: 35 | if e.errno != errno.EEXIST: 36 | raise e 37 | 38 | def load(self, image, address): 39 | cbuf = ctypes.create_string_buffer(bytes(image)) 40 | 41 | load = struct.pack('i4x32sI4xQQQ8x', 42 | JailhouseCell.JAILHOUSE_CELL_ID_UNUSED, self.name, 43 | 1, ctypes.addressof(cbuf), len(image), address) 44 | fcntl.ioctl(self.dev, self.JAILHOUSE_CELL_LOAD, load) 45 | 46 | def start(self): 47 | start = struct.pack('i4x32s', JailhouseCell.JAILHOUSE_CELL_ID_UNUSED, 48 | self.name) 49 | fcntl.ioctl(self.dev, JailhouseCell.JAILHOUSE_CELL_START, start) 50 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/mmio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | /** 16 | * @ingroup IO 17 | * @addtogroup IO-X86 x86 18 | * @{ 19 | */ 20 | 21 | /** Information about MMIO instruction performing an access. */ 22 | struct mmio_instruction { 23 | /** Length of the MMIO access instruction, 0 for invalid or unsupported 24 | * access. */ 25 | unsigned int inst_len; 26 | /** Size of the access. */ 27 | unsigned int access_size; 28 | /** Number of the register that should receive the input. */ 29 | unsigned int in_reg_num; 30 | /** Output value, already copied either from a register or 31 | * from an immediate value */ 32 | unsigned long out_val; 33 | /** A read must not clear the upper bits of registers, if the access 34 | * width is smaller than 32 bit. This mask describes the bits that have 35 | * to be preserved. 36 | */ 37 | unsigned long reg_preserve_mask; 38 | }; 39 | 40 | /** 41 | * Parse instruction causing an intercepted MMIO access on a cell CPU. 42 | * @param pg_structs Currently active guest (cell) paging structures. 43 | * @param is_write True if write access, false for read. 44 | * 45 | * @return MMIO instruction information. mmio_instruction::inst_len is 0 on 46 | * invalid or unsupported access. 47 | */ 48 | struct mmio_instruction 49 | x86_mmio_parse(const struct guest_paging_structures *pg_structs, bool is_write); 50 | 51 | /** @} */ 52 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/psci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | /* PSCI v0.2 interface */ 14 | #define PSCI_0_2_FN(n) (0x84000000 + (n)) 15 | #define PSCI_0_2_FN64(n) (0xc4000000 + (n)) 16 | 17 | #define PSCI_0_2_FN_VERSION PSCI_0_2_FN(0) 18 | #define PSCI_0_2_FN_CPU_SUSPEND PSCI_0_2_FN(1) 19 | #define PSCI_0_2_FN_CPU_OFF PSCI_0_2_FN(2) 20 | #define PSCI_0_2_FN_CPU_ON PSCI_0_2_FN(3) 21 | #define PSCI_0_2_FN_AFFINITY_INFO PSCI_0_2_FN(4) 22 | 23 | #define PSCI_0_2_FN64_CPU_SUSPEND PSCI_0_2_FN64(1) 24 | #define PSCI_0_2_FN64_CPU_ON PSCI_0_2_FN64(3) 25 | #define PSCI_0_2_FN64_AFFINITY_INFO PSCI_0_2_FN64(4) 26 | 27 | /* PSCI v1.0 interface */ 28 | #define PSCI_1_0_FN_FEATURES PSCI_0_2_FN(10) 29 | 30 | /* v0.1 function IDs as used by U-Boot */ 31 | #define PSCI_CPU_OFF_V0_1_UBOOT 0x95c1ba5f 32 | #define PSCI_CPU_ON_V0_1_UBOOT 0x95c1ba60 33 | 34 | #define PSCI_SUCCESS 0 35 | #define PSCI_NOT_SUPPORTED (-1) 36 | #define PSCI_INVALID_PARAMETERS (-2) 37 | #define PSCI_DENIED (-3) 38 | #define PSCI_ALREADY_ON (-4) 39 | 40 | #define PSCI_CPU_IS_ON 0 41 | #define PSCI_CPU_IS_OFF 1 42 | 43 | #define IS_PSCI_UBOOT(hvc) (((hvc) >> 8) == 0x95c1ba) 44 | 45 | #define PSCI_INVALID_ADDRESS (-1L) 46 | 47 | #define PSCI_VERSION_MAJOR(ver) (u16)((ver) >> 16) 48 | #define PSCI_VERSION(major, minor) (((major) << 16) | (minor)) 49 | 50 | struct trap_context; 51 | 52 | long psci_dispatch(struct trap_context *ctx); 53 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/iommu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Valentine Sinitsyn, 2014 5 | * 6 | * Authors: 7 | * Valentine Sinitsyn 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_IOMMU_H 14 | #define _JAILHOUSE_ASM_IOMMU_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | extern unsigned int fault_reporting_cpu_id; 25 | 26 | unsigned int iommu_count_units(void); 27 | 28 | int iommu_map_memory_region(struct cell *cell, 29 | const struct jailhouse_memory *mem); 30 | int iommu_unmap_memory_region(struct cell *cell, 31 | const struct jailhouse_memory *mem); 32 | int iommu_add_pci_device(struct cell *cell, struct pci_device *device); 33 | void iommu_remove_pci_device(struct pci_device *device); 34 | 35 | struct apic_irq_message iommu_get_remapped_root_int(unsigned int iommu, 36 | u16 device_id, 37 | unsigned int vector, 38 | unsigned int remap_index); 39 | int iommu_map_interrupt(struct cell *cell, 40 | u16 device_id, 41 | unsigned int vector, 42 | struct apic_irq_message irq_msg); 43 | 44 | void iommu_config_commit(struct cell *cell_added_removed); 45 | 46 | void iommu_prepare_shutdown(void); 47 | 48 | struct public_per_cpu *iommu_select_fault_reporting_cpu(void); 49 | void iommu_check_pending_faults(void); 50 | 51 | bool iommu_cell_emulates_ir(struct cell *cell); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /hypervisor/include/jailhouse/unit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2018 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | struct unit { 16 | const char *name; 17 | 18 | int (*init)(void); 19 | void (*shutdown)(void); 20 | 21 | unsigned int (*mmio_count_regions)(struct cell *); 22 | int (*cell_init)(struct cell *); 23 | void (*cell_exit)(struct cell *); 24 | }; 25 | 26 | #define DEFINE_UNIT(__name, __description) \ 27 | static const struct unit unit_##__name \ 28 | __attribute__((section(".units"), aligned(8), used)) = { \ 29 | .name = __description, \ 30 | .init = __name##_init, \ 31 | .shutdown = __name##_shutdown, \ 32 | .mmio_count_regions = __name##_mmio_count_regions, \ 33 | .cell_init = __name##_cell_init, \ 34 | .cell_exit = __name##_cell_exit, \ 35 | } 36 | 37 | #define DEFINE_UNIT_SHUTDOWN_STUB(__name) \ 38 | static void __name##_shutdown(void) { } 39 | 40 | #define DEFINE_UNIT_MMIO_COUNT_REGIONS_STUB(__name) \ 41 | static unsigned int __name##_mmio_count_regions(struct cell *cell) \ 42 | { return 0; } 43 | 44 | extern struct unit __unit_array_start[0], __unit_array_end[0]; 45 | 46 | #define for_each_unit(unit) \ 47 | for ((unit) = __unit_array_start; (unit) < __unit_array_end; (unit)++) 48 | 49 | #define for_each_unit_before_reverse(unit, before_unit) \ 50 | for ((unit) = before_unit - 1; (unit) >= __unit_array_start; \ 51 | (unit)--) 52 | 53 | #define for_each_unit_reverse(unit) \ 54 | for_each_unit_before_reverse(unit, __unit_array_end) 55 | -------------------------------------------------------------------------------- /configs/arm64/jetson-tx2-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on Nvidia Jetson TX2: 5 | * 1 CPU, 64 MB RAM, serial port 0 6 | * 7 | * This work is licensed under the terms of the GNU GPL, version 2. See 8 | * the COPYING file in the top-level directory. 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | struct { 15 | struct jailhouse_cell_desc cell; 16 | __u64 cpus[1]; 17 | struct jailhouse_memory mem_regions[3]; 18 | } __attribute__((packed)) config = { 19 | .cell = { 20 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 21 | .revision = JAILHOUSE_CONFIG_REVISION, 22 | .name = "jetson-tx2-inmate-demo", 23 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 24 | 25 | .cpu_set_size = sizeof(config.cpus), 26 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 27 | 28 | .console = { 29 | .address = 0x3100000, 30 | .type = JAILHOUSE_CON_TYPE_8250, 31 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 32 | JAILHOUSE_CON_REGDIST_4, 33 | }, 34 | }, 35 | 36 | .cpus = { 37 | 0x1, 38 | }, 39 | 40 | .mem_regions = { 41 | /* UART */ { 42 | .phys_start = 0x3100000, 43 | .virt_start = 0x3100000, 44 | .size = 0x1000, 45 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 46 | JAILHOUSE_MEM_IO, 47 | }, 48 | /* RAM */ { 49 | .phys_start = 0x270000000, 50 | .virt_start = 0, 51 | .size = 0x1000000, 52 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 53 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 54 | }, 55 | /* communication region */ { 56 | .virt_start = 0x80000000, 57 | .size = 0x00001000, 58 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 59 | JAILHOUSE_MEM_COMM_REGION, 60 | }, 61 | }, 62 | }; 63 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/gic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_GIC_COMMON_H 14 | #define _JAILHOUSE_ASM_GIC_COMMON_H 15 | 16 | #include 17 | 18 | #define GICD_CTLR 0x0000 19 | # define GICD_CTLR_ARE_NS (1 << 4) 20 | #define GICD_TYPER 0x0004 21 | #define GICD_IIDR 0x0008 22 | #define GICD_IGROUPR 0x0080 23 | #define GICD_ISENABLER 0x0100 24 | #define GICD_ICENABLER 0x0180 25 | #define GICD_ISPENDR 0x0200 26 | #define GICD_ICPENDR 0x0280 27 | #define GICD_ISACTIVER 0x0300 28 | #define GICD_ICACTIVER 0x0380 29 | #define GICD_IPRIORITYR 0x0400 30 | #define GICD_ITARGETSR 0x0800 31 | #define GICD_ICFGR 0x0c00 32 | #define GICD_NSACR 0x0e00 33 | #define GICD_SGIR 0x0f00 34 | #define GICD_CPENDSGIR 0x0f10 35 | #define GICD_SPENDSGIR 0x0f20 36 | #define GICD_IROUTER 0x6000 37 | 38 | #define GICD_PIDR2_ARCH(pidr) (((pidr) & 0xf0) >> 4) 39 | 40 | #define is_sgi(irqn) ((u32)(irqn) < 16) 41 | #define is_ppi(irqn) ((irqn) > 15 && (irqn) < 32) 42 | #define is_spi(irqn) ((irqn) > 31 && (irqn) < 1020) 43 | 44 | #define REG_RANGE(base, n, size) (base)...((base) + (n - 1) * (size)) 45 | 46 | #ifndef __ASSEMBLY__ 47 | extern const struct irqchip gicv2_irqchip, gicv3_irqchip; 48 | 49 | extern void *gicd_base; 50 | extern spinlock_t dist_lock; 51 | 52 | void gic_handle_sgir_write(struct sgi *sgi); 53 | bool gicv3_handle_sgir_write(u64 sgir); 54 | #endif /* !__ASSEMBLY__ */ 55 | #endif /* !_JAILHOUSE_ASM_GIC_COMMON_H */ 56 | -------------------------------------------------------------------------------- /Documentation/coding-style.txt: -------------------------------------------------------------------------------- 1 | Coding style 2 | ============ 3 | 4 | This document sets the coding style for Jailhouse code contributions. 5 | In general, Jailhouse coding style for C is the same as for Linux kernel 6 | (checkable with scripts/checkpatch.pl and detailed in 7 | Documentation/CodingStyle), but with some notable variations and clarifications 8 | described here (in random order): 9 | 10 | * Align function arguments vertically when wrapping over line breaks: 11 | 12 | void rather_long_function_name(struct another_rather_long_name *argument1, 13 | struct yet_another_long_name *argument2); 14 | 15 | * Avoid conditional compilation (#ifdefs) where possible (and it's almost 16 | always possible). Variations should be resolved during link time, or 17 | (if absolutely necessary) in the runtime (but think about performance). 18 | 19 | * Do not explicitly initialize static variables you want zeroed. C standard 20 | ensures this by default. 21 | 22 | * Do not insert blank lines in #include list, except to separate include blocks 23 | where the second depends on the first one, e.g. 24 | 25 | #include 26 | 27 | #include 28 | 29 | * Always include generic headers ("jailhouse/*.h") before architecture 30 | headers ("asm/*.h"). 31 | 32 | * Header files must be self-standing, i.e. must not rely on other headers being 33 | included prior to them. Use scripts/header_check to validate. 34 | 35 | * Spaces in brackets are permitted for designated initializers in order to 36 | improve readability via vertical alignment: 37 | 38 | [ 0/8 ... 0x1f/8] = 0, /* floppy DMA controller */ 39 | [ 0x20/8 ... 0x3f/8] = -1, 40 | [ 0x40/8 ... 0x47/8] = 0xf0, /* PIT */ 41 | 42 | For Python code, stick to PEP-8. 43 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2013, 2014 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | 13 | # Check make version 14 | need := 3.82 15 | ifneq ($(need),$(firstword $(sort $(MAKE_VERSION) $(need)))) 16 | $(error Too old make version $(MAKE_VERSION), at least $(need) required) 17 | endif 18 | 19 | # no recipes above this one (also no includes) 20 | all: modules 21 | 22 | # includes installation-related variables and definitions 23 | include scripts/include.mk 24 | 25 | # out-of-tree build for our kernel-module, firmware and inmates 26 | KDIR ?= /lib/modules/`uname -r`/build 27 | 28 | INSTALL_MOD_PATH ?= $(DESTDIR) 29 | export INSTALL_MOD_PATH 30 | 31 | DOXYGEN ?= doxygen 32 | 33 | kbuild = -C $(KDIR) M=$$PWD $@ 34 | 35 | ifneq ($(DESTDIR),) 36 | PIP_ROOT = --root=$(shell readlink -f $(DESTDIR)) 37 | endif 38 | 39 | modules clean: 40 | $(Q)$(MAKE) $(kbuild) 41 | 42 | # documentation, build needs to be triggered explicitly 43 | docs: 44 | $(DOXYGEN) Documentation/Doxyfile 45 | 46 | modules_install: modules 47 | $(Q)$(MAKE) $(kbuild) 48 | 49 | firmware_install: $(DESTDIR)$(firmwaredir) modules 50 | $(INSTALL_DATA) hypervisor/jailhouse*.bin $< 51 | 52 | tool_inmates_install: $(DESTDIR)$(libexecdir)/jailhouse 53 | $(INSTALL_DATA) inmates/tools/$(ARCH)/*.bin $< 54 | 55 | install: modules_install firmware_install tool_inmates_install 56 | $(Q)$(MAKE) -C tools $@ src=. 57 | ifeq ($(strip $(PYTHON_PIP_USABLE)), yes) 58 | $(PIP) install --upgrade --force-reinstall $(PIP_ROOT) . 59 | endif 60 | 61 | .PHONY: modules_install install clean firmware_install modules tools docs \ 62 | docs_clean 63 | -------------------------------------------------------------------------------- /inmates/demos/x86/ioapic-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * 13 | * WARNING: This is just a demo, using a commonly available resource. IRQ 9 14 | * is bluntly stolen from Linux while it may still listen to this source in 15 | * the ACPI driver. Even when destroying the cell, Linux won't regain control 16 | * as it won't reprogram the IOAPIC. Moreover, the IRQ might be shared with 17 | * other devices which will lose their IRQs when starting this cell. 18 | * 19 | * Strong recommendation: Avoid using legacy interrupt for non-root cells! 20 | * Many of them can't be isolated easily from other other cells - if at all. 21 | */ 22 | 23 | #include 24 | 25 | #define PM1_STATUS 0 26 | #define PM1_ENABLE 2 27 | # define PM1_TMR_EN (1 << 0) 28 | 29 | #define ACPI_GSI 9 30 | 31 | #define IRQ_VECTOR 32 32 | 33 | static unsigned int pm_base; 34 | 35 | static void irq_handler(unsigned int irq) 36 | { 37 | u16 status; 38 | 39 | if (irq != IRQ_VECTOR) 40 | return; 41 | 42 | status = inw(pm_base + PM1_STATUS); 43 | 44 | printk("ACPI IRQ received, status: %04x\n", status); 45 | outw(status, pm_base); 46 | } 47 | 48 | void inmate_main(void) 49 | { 50 | irq_init(irq_handler); 51 | 52 | ioapic_init(); 53 | ioapic_pin_set_vector(ACPI_GSI, TRIGGER_LEVEL_ACTIVE_HIGH, IRQ_VECTOR); 54 | 55 | pm_base = comm_region->pm_timer_address - 8; 56 | outw(inw(pm_base + PM1_ENABLE) | PM1_TMR_EN, pm_base + PM1_ENABLE); 57 | 58 | printk("Note: ACPI IRQs are broken for Linux now.\n"); 59 | asm volatile("sti"); 60 | 61 | halt(); 62 | } 63 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/processor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_PROCESSOR_H 14 | #define _JAILHOUSE_ASM_PROCESSOR_H 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #define EXIT_REASON_UNDEF 0x1 21 | #define EXIT_REASON_HVC 0x2 22 | #define EXIT_REASON_PABT 0x3 23 | #define EXIT_REASON_DABT 0x4 24 | #define EXIT_REASON_TRAP 0x5 25 | #define EXIT_REASON_IRQ 0x6 26 | #define EXIT_REASON_FIQ 0x7 27 | 28 | #define NUM_USR_REGS 14 29 | 30 | #ifndef __ASSEMBLY__ 31 | 32 | union registers { 33 | struct { 34 | unsigned long exit_reason; 35 | /* r0 - r12 and lr. The other registers are banked. */ 36 | unsigned long usr[NUM_USR_REGS]; 37 | }; 38 | }; 39 | 40 | #define ARM_PARKING_CODE \ 41 | 0xe320f003, /* 1: wfi */ \ 42 | 0xeafffffd, /* b 1b */ 43 | 44 | #define dmb(domain) asm volatile("dmb " #domain ::: "memory") 45 | #define dsb(domain) asm volatile("dsb " #domain ::: "memory") 46 | #define isb() asm volatile("isb") 47 | 48 | static inline void cpu_relax(void) 49 | { 50 | asm volatile("" : : : "memory"); 51 | } 52 | 53 | static inline void memory_barrier(void) 54 | { 55 | dmb(ish); 56 | } 57 | 58 | static inline void memory_load_barrier(void) 59 | { 60 | dmb(ish); 61 | } 62 | 63 | static inline bool is_el2(void) 64 | { 65 | u32 psr; 66 | 67 | asm volatile ("mrs %0, cpsr" : "=r" (psr)); 68 | 69 | return (psr & PSR_MODE_MASK) == PSR_HYP_MODE; 70 | } 71 | 72 | #endif /* !__ASSEMBLY__ */ 73 | 74 | #endif /* !_JAILHOUSE_ASM_PROCESSOR_H */ 75 | -------------------------------------------------------------------------------- /hypervisor/arch/arm64/asm-defines.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse AArch64 support 3 | * 4 | * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 5 | * Copyright (c) Siemens AG, 2016 6 | * 7 | * Authors: 8 | * Antonios Motakis 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | void common(void); 20 | 21 | void common(void) 22 | { 23 | OFFSET(HEADER_MAX_CPUS, jailhouse_header, max_cpus); 24 | OFFSET(HEADER_CORE_SIZE, jailhouse_header, core_size); 25 | OFFSET(HEADER_DEBUG_CONSOLE_VIRT, jailhouse_header, debug_console_base); 26 | OFFSET(HEADER_HYP_STUB_VERSION, jailhouse_header, arm_linux_hyp_abi); 27 | OFFSET(SYSCONFIG_DEBUG_CONSOLE_PHYS, jailhouse_system, 28 | debug_console.address); 29 | OFFSET(SYSCONFIG_HYPERVISOR_PHYS, jailhouse_system, 30 | hypervisor_memory.phys_start); 31 | OFFSET(PERCPU_ID_AA64MMFR0, per_cpu, id_aa64mmfr0); 32 | BLANK(); 33 | 34 | DEFINE(PERCPU_STACK_END, 35 | __builtin_offsetof(struct per_cpu, stack) + \ 36 | FIELD_SIZEOF(struct per_cpu, stack)); 37 | DEFINE(PERCPU_SIZE_ASM, sizeof(struct per_cpu)); 38 | DEFINE(CPU_STAT_VMEXITS_TOTAL, LOCAL_CPU_BASE + 39 | __builtin_offsetof(struct per_cpu, 40 | public.stats[JAILHOUSE_CPU_STAT_VMEXITS_TOTAL])); 41 | DEFINE(CPU_STAT_VMEXITS_SMCCC, LOCAL_CPU_BASE + 42 | __builtin_offsetof(struct per_cpu, 43 | public.stats[JAILHOUSE_CPU_STAT_VMEXITS_SMCCC])); 44 | BLANK(); 45 | 46 | DEFINE(DCACHE_CLEAN_ASM, DCACHE_CLEAN); 47 | DEFINE(DCACHE_INVALIDATE_ASM, DCACHE_INVALIDATE); 48 | DEFINE(DCACHE_CLEAN_AND_INVALIDATE_ASM, DCACHE_CLEAN_AND_INVALIDATE); 49 | } 50 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/caches.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | /* 17 | * Clean the whole data cache 18 | * Taken from the ARM ARM example code (B2.2.7) 19 | */ 20 | .global arm_dcaches_clean_by_sw 21 | arm_dcaches_clean_by_sw: 22 | push {r0-r10} 23 | 24 | dsb 25 | arm_read_sysreg(CLIDR_EL1, r0) 26 | ands r3, r0, #0x07000000 27 | lsr r3, #23 @ Extract level of coherency 28 | beq finish 29 | 30 | mov r9, #0 @ Cache level - 1 31 | @ Loop caches 32 | loop_caches: 33 | add r2, r9, r9, lsr #1 34 | lsr r1, r0, r2 @ Extract current level type 35 | and r1, r1, #7 36 | cmp r1, #2 37 | blt next_cache @ No cache or instruction only 38 | 39 | arm_write_sysreg(CSSELR_EL1, r9) 40 | isb @ sync selector change 41 | arm_read_sysreg(CSSIDR_EL1, r1) 42 | 43 | and r2, r1, #7 @ extract log2(line size - 4) 44 | add r2, #4 45 | ldr r4, =0x3ff 46 | ands r4, r4, r1, lsr #3 47 | clz r5, r4 @ Max way size 48 | mov r8, r5 @ Working copy of the way size 49 | 50 | loop_sets: 51 | ldr r7, =0x7fff 52 | ands r7, r7, r1, lsr #13 @ Max number of index size 53 | loop_ways: 54 | orr r10, r9, r8, lsl r5 @ Factor in the way and cache numbers 55 | orr r10, r10, r7, lsl r2 @ Factor in the index number 56 | 57 | arm_write_sysreg(DCCSW, r10) 58 | 59 | subs r7, r7, #1 @ decrement index 60 | bge loop_ways 61 | subs r8, r8, #1 @ decrement way 62 | bge loop_sets 63 | 64 | next_cache: 65 | add r9, r9, #2 @ increment cache number 66 | cmp r3, r9 67 | bgt loop_caches 68 | dsb 69 | 70 | finish: isb 71 | pop {r0-r10} 72 | bx lr 73 | -------------------------------------------------------------------------------- /inmates/lib/arm64/include/arch/gic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) OTH Regensburg, 2017 5 | * 6 | * Authors: 7 | * Ralf Ramsauer 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * Alternatively, you can use or redistribute this file under the following 13 | * BSD license: 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 19 | * 1. Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 36 | * THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #define gic_setup_irq_stack() 40 | -------------------------------------------------------------------------------- /driver/pci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014-2015 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * Henning Schild 9 | * 10 | * This work is licensed under the terms of the GNU GPL, version 2. See 11 | * the COPYING file in the top-level directory. 12 | */ 13 | 14 | #include "cell.h" 15 | 16 | enum { 17 | JAILHOUSE_PCI_ACTION_ADD, JAILHOUSE_PCI_ACTION_DEL, 18 | JAILHOUSE_PCI_ACTION_CLAIM, JAILHOUSE_PCI_ACTION_RELEASE, 19 | }; 20 | 21 | #ifdef CONFIG_PCI 22 | 23 | void jailhouse_pci_do_all_devices(struct cell *cell, unsigned int type, 24 | unsigned int action); 25 | int jailhouse_pci_cell_setup(struct cell *cell, 26 | const struct jailhouse_cell_desc *cell_desc); 27 | void jailhouse_pci_cell_cleanup(struct cell *cell); 28 | void jailhouse_pci_virtual_root_devices_add(struct jailhouse_system *config); 29 | void jailhouse_pci_virtual_root_devices_remove(void); 30 | int jailhouse_pci_register(void); 31 | void jailhouse_pci_unregister(void); 32 | 33 | #else /* !CONFIG_PCI */ 34 | 35 | static inline void 36 | jailhouse_pci_do_all_devices(struct cell *cell, unsigned int type, 37 | unsigned int action) 38 | { 39 | } 40 | 41 | static inline int 42 | jailhouse_pci_cell_setup(struct cell *cell, 43 | const struct jailhouse_cell_desc *cell_desc) 44 | { 45 | return 0; 46 | } 47 | 48 | static inline void jailhouse_pci_cell_cleanup(struct cell *cell) 49 | { 50 | } 51 | 52 | static inline void 53 | jailhouse_pci_virtual_root_devices_add(struct jailhouse_system *config) 54 | { 55 | } 56 | 57 | static inline void jailhouse_pci_virtual_root_devices_remove(void) 58 | { 59 | } 60 | 61 | static inline int jailhouse_pci_register(void) 62 | { 63 | return 0; 64 | } 65 | 66 | static inline void jailhouse_pci_unregister(void) 67 | { 68 | } 69 | 70 | #endif /* !CONFIG_PCI */ 71 | -------------------------------------------------------------------------------- /configs/arm64/jetson-tx1-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on Nvidia Jetson TX1: 5 | * 1 CPU, 64K RAM, serial port 0 6 | * 7 | * Copyright (c) Siemens AG, 2015 8 | * 9 | * Authors: 10 | * Jan Kiszka 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "jetson-tx1-inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | 33 | .console = { 34 | .address = 0x70006000, 35 | .type = JAILHOUSE_CON_TYPE_8250, 36 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 37 | JAILHOUSE_CON_REGDIST_4, 38 | }, 39 | }, 40 | 41 | .cpus = { 42 | 0x8, 43 | }, 44 | 45 | .mem_regions = { 46 | /* UART */ { 47 | .phys_start = 0x70006000, 48 | .virt_start = 0x70006000, 49 | .size = 0x1000, 50 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 51 | JAILHOUSE_MEM_IO, 52 | }, 53 | /* RAM */ { 54 | .phys_start = 0x17bef0000, 55 | .virt_start = 0, 56 | .size = 0x00010000, 57 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 58 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 59 | }, 60 | /* communication region */ { 61 | .virt_start = 0x80000000, 62 | .size = 0x00001000, 63 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 64 | JAILHOUSE_MEM_COMM_REGION, 65 | }, 66 | }, 67 | }; 68 | -------------------------------------------------------------------------------- /driver/cell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014-2016 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_DRIVER_CELL_H 14 | #define _JAILHOUSE_DRIVER_CELL_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "jailhouse.h" 22 | 23 | #include 24 | 25 | struct cell { 26 | struct kobject kobj; 27 | struct kobject stats_kobj; 28 | struct list_head cell_cpus; 29 | struct list_head entry; 30 | unsigned int id; 31 | char name[JAILHOUSE_CELL_ID_NAMELEN+1]; 32 | cpumask_t cpus_assigned; 33 | u32 num_memory_regions; 34 | struct jailhouse_memory *memory_regions; 35 | u32 num_memory_regions_colored; 36 | struct jailhouse_memory_colored *memory_regions_colored; 37 | #ifdef CONFIG_PCI 38 | u32 num_pci_devices; 39 | struct jailhouse_pci_device *pci_devices; 40 | #endif /* CONFIG_PCI */ 41 | }; 42 | 43 | extern struct cell *root_cell; 44 | 45 | void jailhouse_cell_kobj_release(struct kobject *kobj); 46 | 47 | int jailhouse_cell_prepare_root(const struct jailhouse_cell_desc *cell_desc); 48 | void jailhouse_cell_register_root(void); 49 | void jailhouse_cell_delete_root(void); 50 | 51 | int jailhouse_cmd_cell_create(struct jailhouse_cell_create __user *arg); 52 | int jailhouse_cmd_cell_load(struct jailhouse_cell_load __user *arg); 53 | int jailhouse_cmd_cell_start(const char __user *arg); 54 | int jailhouse_cmd_cell_destroy(const char __user *arg); 55 | 56 | int jailhouse_cmd_cell_destroy_non_root(void); 57 | 58 | int jailhouse_cmd_cell_memguard(struct jailhouse_memguard_args __user *arg); 59 | 60 | #endif /* !_JAILHOUSE_DRIVER_CELL_H */ 61 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/uart-pl011.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #define UART_CLK 24000000 18 | 19 | #define UARTDR 0x00 20 | #define UARTFR 0x18 21 | #define UARTIBRD 0x24 22 | #define UARTLCR_H 0x2c 23 | #define UARTCR 0x30 24 | 25 | #define UARTFR_TXFF (1 << 5) 26 | #define UARTFR_BUSY (1 << 3) 27 | 28 | #define UARTCR_Out2 (1 << 13) 29 | #define UARTCR_Out1 (1 << 12) 30 | #define UARTCR_RXE (1 << 9) 31 | #define UARTCR_TXE (1 << 8) 32 | #define UARTCR_EN (1 << 0) 33 | 34 | #define UARTLCR_H_WLEN (3 << 5) 35 | 36 | static void uart_init(struct uart_chip *chip) 37 | { 38 | unsigned int divider = chip->debug_console->divider; 39 | void *base = chip->virt_base; 40 | 41 | if (divider) { 42 | mmio_write16(base + UARTCR, 0); 43 | while (mmio_read8(base + UARTFR) & UARTFR_BUSY) 44 | cpu_relax(); 45 | mmio_write16(base + UARTIBRD, divider); 46 | mmio_write8(base + UARTLCR_H, UARTLCR_H_WLEN); 47 | mmio_write16(base + UARTCR, UARTCR_EN | UARTCR_TXE | 48 | UARTCR_Out1 | UARTCR_Out2); 49 | } 50 | } 51 | 52 | static bool uart_is_busy(struct uart_chip *chip) 53 | { 54 | /* FIFO full or busy */ 55 | return (mmio_read32(chip->virt_base + UARTFR) & 56 | (UARTFR_TXFF | UARTFR_BUSY)) != 0; 57 | } 58 | 59 | static void uart_write_char(struct uart_chip *chip, char c) 60 | { 61 | mmio_write32(chip->virt_base + UARTDR, c); 62 | } 63 | 64 | struct uart_chip uart_pl011_ops = { 65 | .init = uart_init, 66 | .is_busy = uart_is_busy, 67 | .write_char = uart_write_char, 68 | }; 69 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/pci.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2016 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | u32 arch_pci_read_config(u16 bdf, u16 address, unsigned int size) 17 | { 18 | return -1; 19 | } 20 | 21 | void arch_pci_write_config(u16 bdf, u16 address, u32 value, unsigned int size) 22 | { 23 | } 24 | 25 | int arch_pci_add_physical_device(struct cell *cell, struct pci_device *device) 26 | { 27 | return 0; 28 | } 29 | 30 | void arch_pci_remove_physical_device(struct pci_device *device) 31 | { 32 | } 33 | 34 | void arch_pci_set_suppress_msi(struct pci_device *device, 35 | const struct jailhouse_pci_capability *cap, 36 | bool suppress) 37 | { 38 | } 39 | 40 | int arch_pci_update_msi(struct pci_device *device, 41 | const struct jailhouse_pci_capability *cap) 42 | { 43 | const struct jailhouse_pci_device *info = device->info; 44 | unsigned int n; 45 | 46 | /* 47 | * NOTE: We don't have interrupt remapping yet. So we write the values 48 | * the cell passed without modifications. Probably not safe on all 49 | * platforms. 50 | */ 51 | for (n = 1; n < (info->msi_64bits ? 4 : 3); n++) 52 | pci_write_config(info->bdf, cap->start + n * 4, 53 | device->msi_registers.raw[n], 4); 54 | 55 | return 0; 56 | } 57 | 58 | int arch_pci_update_msix_vector(struct pci_device *device, unsigned int index) 59 | { 60 | /* NOTE: See arch_pci_update_msi. */ 61 | mmio_write64_split(&device->msix_table[index].address, 62 | device->msix_vectors[index].address); 63 | mmio_write32(&device->msix_table[index].data, 64 | device->msix_vectors[index].data); 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/ivshmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2014-2019 5 | * 6 | * Author: 7 | * Henning Schild 8 | * Jan Kiszka 9 | * 10 | * This work is licensed under the terms of the GNU GPL, version 2. See 11 | * the COPYING file in the top-level directory. 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void arch_ivshmem_trigger_interrupt(struct ivshmem_endpoint *ive, 21 | unsigned int vector) 22 | { 23 | if (ive->irq_cache.msg[vector].valid) 24 | apic_send_irq(ive->irq_cache.msg[vector]); 25 | } 26 | 27 | int arch_ivshmem_update_msix(struct ivshmem_endpoint *ive, unsigned int vector, 28 | bool enabled) 29 | { 30 | struct apic_irq_message irq_msg = { .valid = 0 }; 31 | struct pci_device *device = ive->device; 32 | union x86_msi_vector msi; 33 | 34 | if (enabled) { 35 | msi.raw.address = device->msix_vectors[vector].address; 36 | msi.raw.data = device->msix_vectors[vector].data; 37 | 38 | irq_msg = x86_pci_translate_msi(device, vector, 0, msi); 39 | 40 | if (irq_msg.valid && 41 | !apic_filter_irq_dest(device->cell, &irq_msg)) { 42 | panic_printk("FATAL: ivshmem MSI-X target outside of " 43 | "cell \"%s\" device %02x:%02x.%x\n", 44 | device->cell->config->name, 45 | PCI_BDF_PARAMS(device->info->bdf)); 46 | return -EPERM; 47 | } 48 | } 49 | 50 | /* 51 | * Lock used as barrier, ensuring all interrupts triggered after return 52 | * use the new setting. 53 | */ 54 | spin_lock(&ive->irq_lock); 55 | ive->irq_cache.msg[vector] = irq_msg; 56 | spin_unlock(&ive->irq_lock); 57 | 58 | return 0; 59 | } 60 | 61 | void arch_ivshmem_update_intx(struct ivshmem_endpoint *ive, bool enabled) 62 | { 63 | } 64 | -------------------------------------------------------------------------------- /inmates/lib/include/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) OTH Regensburg, 2019 5 | * 6 | * Authors: 7 | * Ralf Ramsauer 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * Alternatively, you can use or redistribute this file under the following 13 | * BSD license: 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 19 | * 1. Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 36 | * THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #define __stringify_1(x...) #x 40 | #define __stringify(x...) __stringify_1(x) 41 | -------------------------------------------------------------------------------- /inmates/lib/arm-common/setup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) OTH Regensburg, 2018 5 | * 6 | * Authors: 7 | * Ralf Ramsauer 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * Alternatively, you can use or redistribute this file under the following 13 | * BSD license: 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 19 | * 1. Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 36 | * THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | 41 | void arch_init_early(void) 42 | { 43 | arch_mmu_enable(); 44 | } 45 | -------------------------------------------------------------------------------- /configs/arm64/foundation-v8-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on Foundation Model v8: 5 | * 1 CPU, 64K RAM, serial port 1 6 | * 7 | * Copyright (c) ARM Limited, 2014 8 | * 9 | * Authors: 10 | * Jean-Philippe Brucker 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | .num_irqchips = 0, 33 | .num_pci_devices = 0, 34 | 35 | .console = { 36 | .address = 0x1c090000, 37 | .type = JAILHOUSE_CON_TYPE_PL011, 38 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 39 | JAILHOUSE_CON_REGDIST_4, 40 | }, 41 | }, 42 | 43 | .cpus = { 44 | 0x2, 45 | }, 46 | 47 | .mem_regions = { 48 | /* UART 1 */ { 49 | .phys_start = 0x1c0a0000, 50 | .virt_start = 0x1c090000, 51 | .size = 0x10000, 52 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 53 | JAILHOUSE_MEM_IO, 54 | }, 55 | /* RAM */ { 56 | .phys_start = 0xfbfe0000, 57 | .virt_start = 0, 58 | .size = 0x00010000, 59 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 60 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 61 | }, 62 | /* communication region */ { 63 | .virt_start = 0x80000000, 64 | .size = 0x00001000, 65 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 66 | JAILHOUSE_MEM_COMM_REGION, 67 | }, 68 | }, 69 | }; 70 | -------------------------------------------------------------------------------- /configs/arm64/hikey-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on LeMaker HiKey board, 2GiB: 5 | * 1 CPU, 64K RAM, 1 serial port 6 | * 7 | * Copyright (c) Siemens AG, 2016 8 | * 9 | * Authors: 10 | * Jan Kiszka 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | .num_irqchips = 0, 33 | .num_pci_devices = 0, 34 | 35 | .console = { 36 | .address = 0xf7113000, 37 | .type = JAILHOUSE_CON_TYPE_PL011, 38 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 39 | JAILHOUSE_CON_REGDIST_4, 40 | }, 41 | }, 42 | 43 | .cpus = { 44 | 0x10, 45 | }, 46 | 47 | .mem_regions = { 48 | /* UART */ { 49 | .phys_start = 0xf7113000, 50 | .virt_start = 0xf7113000, 51 | .size = 0x1000, 52 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 53 | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, 54 | }, 55 | /* RAM */ { 56 | .phys_start = 0x7bfe0000, 57 | .virt_start = 0, 58 | .size = 0x00010000, 59 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 60 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 61 | }, 62 | /* communication region */ { 63 | .virt_start = 0x80000000, 64 | .size = 0x00001000, 65 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 66 | JAILHOUSE_MEM_COMM_REGION, 67 | }, 68 | } 69 | }; 70 | -------------------------------------------------------------------------------- /configs/arm64/espressobin-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on Marvell ESPRESSObin board: 5 | * 1 CPU, 64K RAM, 1 serial port 6 | * 7 | * Copyright (c) Siemens AG, 2017 8 | * 9 | * Authors: 10 | * Jan Kiszka 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | .num_irqchips = 0, 33 | .num_pci_devices = 0, 34 | 35 | .console = { 36 | .address = 0xd0012000, 37 | .type = JAILHOUSE_CON_TYPE_MVEBU, 38 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 39 | JAILHOUSE_CON_REGDIST_4, 40 | }, 41 | }, 42 | 43 | .cpus = { 44 | 0x2, 45 | }, 46 | 47 | .mem_regions = { 48 | /* UART */ { 49 | .phys_start = 0xd0012000, 50 | .virt_start = 0xd0012000, 51 | .size = 0x1000, 52 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 53 | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, 54 | }, 55 | /* RAM */ { 56 | .phys_start = 0x3faf0000, 57 | .virt_start = 0, 58 | .size = 0x00010000, 59 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 60 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 61 | }, 62 | /* communication region */ { 63 | .virt_start = 0x80000000, 64 | .size = 0x00001000, 65 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 66 | JAILHOUSE_MEM_COMM_REGION, 67 | }, 68 | } 69 | }; 70 | -------------------------------------------------------------------------------- /configs/arm64/macchiatobin-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on Marvell MACCHIATObin board: 5 | * 1 CPU, 64K RAM, 1 serial port 6 | * 7 | * Copyright (c) Siemens AG, 2017-2018 8 | * 9 | * Authors: 10 | * Jan Kiszka 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | .num_irqchips = 0, 33 | .num_pci_devices = 0, 34 | 35 | .console = { 36 | .address = 0xf0512000, 37 | .type = JAILHOUSE_CON_TYPE_8250, 38 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 39 | JAILHOUSE_CON_REGDIST_4, 40 | }, 41 | }, 42 | 43 | .cpus = { 44 | 0x2, 45 | }, 46 | 47 | .mem_regions = { 48 | /* UART */ { 49 | .phys_start = 0xf0512000, 50 | .virt_start = 0xf0512000, 51 | .size = 0x1000, 52 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 53 | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, 54 | }, 55 | /* RAM */ { 56 | .phys_start = 0x13faf0000, 57 | .virt_start = 0, 58 | .size = 0x00010000, 59 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 60 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 61 | }, 62 | /* communication region */ { 63 | .virt_start = 0x80000000, 64 | .size = 0x00001000, 65 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 66 | JAILHOUSE_MEM_COMM_REGION, 67 | }, 68 | } 69 | }; 70 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/uart-hscif.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) emtrion GmbH, 2017 5 | * 6 | * Authors: 7 | * Ruediger Fichter 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #define HSCIF_HSBRR 0x04 18 | #define HSCIF_HSSCR 0x08 19 | #define HSCIF_HSFTDR 0x0C 20 | #define HSCIF_HSFSR 0x10 21 | #define HSCIF_HSTTRGR 0x58 22 | 23 | #define HSCIF_HSSCR_RE 0x0010 24 | #define HSCIF_HSSCR_TE 0x0020 25 | 26 | #define HSCIF_HSFSR_TDFE 0x0020 27 | #define HSCIF_HSFSR_TEND 0x0040 28 | 29 | #define HSCIF_FIFO_SIZE 128 30 | 31 | static void uart_init(struct uart_chip *chip) 32 | { 33 | u16 hsscr; 34 | 35 | if (chip->debug_console->divider) { 36 | hsscr = mmio_read16(chip->virt_base + HSCIF_HSSCR); 37 | mmio_write16(chip->virt_base + HSCIF_HSSCR, 38 | hsscr & ~(HSCIF_HSSCR_TE | HSCIF_HSSCR_RE)); 39 | mmio_write8(chip->virt_base + HSCIF_HSBRR, 40 | chip->debug_console->divider); 41 | mmio_write16(chip->virt_base + HSCIF_HSTTRGR, 42 | HSCIF_FIFO_SIZE / 2); 43 | mmio_write16(chip->virt_base + HSCIF_HSSCR, 44 | hsscr | HSCIF_HSSCR_TE); 45 | } 46 | } 47 | 48 | static bool uart_is_busy(struct uart_chip *chip) 49 | { 50 | return !(mmio_read16(chip->virt_base + HSCIF_HSFSR) & 51 | HSCIF_HSFSR_TDFE); 52 | } 53 | 54 | static void uart_write_char(struct uart_chip *chip, char c) 55 | { 56 | mmio_write8(chip->virt_base + HSCIF_HSFTDR, c); 57 | mmio_write16(chip->virt_base + HSCIF_HSFSR, 58 | mmio_read16(chip->virt_base + HSCIF_HSFSR) & 59 | ~(HSCIF_HSFSR_TDFE | HSCIF_HSFSR_TEND)); 60 | } 61 | 62 | struct uart_chip uart_hscif_ops = { 63 | .init = uart_init, 64 | .is_busy = uart_is_busy, 65 | .write_char = uart_write_char, 66 | }; 67 | -------------------------------------------------------------------------------- /inmates/lib/arm64/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2015 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | # Alternatively, you can use or redistribute this file under the following 13 | # BSD license: 14 | # 15 | # Redistribution and use in source and binary forms, with or without 16 | # modification, are permitted provided that the following conditions 17 | # are met: 18 | # 19 | # 1. Redistributions of source code must retain the above copyright 20 | # notice, this list of conditions and the following disclaimer. 21 | # 22 | # 2. Redistributions in binary form must reproduce the above copyright 23 | # notice, this list of conditions and the following disclaimer in the 24 | # documentation and/or other materials provided with the distribution. 25 | # 26 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 36 | # THE POSSIBILITY OF SUCH DAMAGE. 37 | # 38 | 39 | include $(INMATES_LIB)/Makefile.lib 40 | include $(INMATES_LIB)/../arm-common/Makefile.lib 41 | 42 | always := lib.a inmate.lds 43 | 44 | lib-y := $(common-objs-y) 45 | lib-y += header.o 46 | -------------------------------------------------------------------------------- /configs/arm64/zynqmp-zcu102-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on Xilinx ZynqMP ZCU102 eval board: 5 | * 1 CPU, 64K RAM, 1 serial port 6 | * 7 | * Copyright (c) Siemens AG, 2016 8 | * 9 | * Authors: 10 | * Jan Kiszka 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | .num_irqchips = 0, 33 | .num_pci_devices = 0, 34 | 35 | .console = { 36 | .address = 0xff010000, 37 | .type = JAILHOUSE_CON_TYPE_XUARTPS, 38 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 39 | JAILHOUSE_CON_REGDIST_4, 40 | }, 41 | }, 42 | 43 | .cpus = { 44 | 0x8, 45 | }, 46 | 47 | .mem_regions = { 48 | /* UART */ { 49 | .phys_start = 0xff010000, 50 | .virt_start = 0xff010000, 51 | .size = 0x1000, 52 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 53 | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, 54 | }, 55 | /* RAM */ { 56 | .phys_start = 0x801200000, 57 | .virt_start = 0, 58 | .size = 0x00010000, 59 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 60 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 61 | }, 62 | /* communication region */ { 63 | .virt_start = 0x80000000, 64 | .size = 0x00001000, 65 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 66 | JAILHOUSE_MEM_COMM_REGION, 67 | }, 68 | } 69 | }; 70 | -------------------------------------------------------------------------------- /configs/x86/smp-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Minimal configuration for SMP demo inmates, 3 CPUs, 1 MB RAM, serial ports 5 | * 6 | * Copyright (c) Siemens AG, 2013-2015 7 | * 8 | * Authors: 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | struct { 19 | struct jailhouse_cell_desc cell; 20 | __u64 cpus[1]; 21 | struct jailhouse_memory mem_regions[2]; 22 | struct jailhouse_pio pio_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "smp-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG | 29 | JAILHOUSE_CELL_VIRTUAL_CONSOLE_PERMITTED, 30 | 31 | .cpu_set_size = sizeof(config.cpus), 32 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 33 | .num_irqchips = 0, 34 | .num_pio_regions = ARRAY_SIZE(config.pio_regions), 35 | .num_pci_devices = 0, 36 | 37 | .console = { 38 | .type = JAILHOUSE_CON_TYPE_8250, 39 | .flags = JAILHOUSE_CON_ACCESS_PIO, 40 | .address = 0x3f8, 41 | }, 42 | }, 43 | 44 | .cpus = { 45 | 0xe, 46 | }, 47 | 48 | .mem_regions = { 49 | /* RAM */ { 50 | .phys_start = 0x3ee00000, 51 | .virt_start = 0, 52 | .size = 0x00100000, 53 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 54 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 55 | }, 56 | /* communication region */ { 57 | .virt_start = 0x00100000, 58 | .size = 0x00001000, 59 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 60 | JAILHOUSE_MEM_COMM_REGION, 61 | }, 62 | }, 63 | 64 | .pio_regions = { 65 | PIO_RANGE(0x2f8, 8), /* serial 2 */ 66 | PIO_RANGE(0x3f8, 8), /* serial 1 */ 67 | PIO_RANGE(0xe010, 8), /* OXPCIe952 serial2 */ 68 | }, 69 | }; 70 | -------------------------------------------------------------------------------- /inmates/lib/arm/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2015, 2016 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # 9 | # This work is licensed under the terms of the GNU GPL, version 2. See 10 | # the COPYING file in the top-level directory. 11 | # 12 | # Alternatively, you can use or redistribute this file under the following 13 | # BSD license: 14 | # 15 | # Redistribution and use in source and binary forms, with or without 16 | # modification, are permitted provided that the following conditions 17 | # are met: 18 | # 19 | # 1. Redistributions of source code must retain the above copyright 20 | # notice, this list of conditions and the following disclaimer. 21 | # 22 | # 2. Redistributions in binary form must reproduce the above copyright 23 | # notice, this list of conditions and the following disclaimer in the 24 | # documentation and/or other materials provided with the distribution. 25 | # 26 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 36 | # THE POSSIBILITY OF SUCH DAMAGE. 37 | # 38 | 39 | include $(INMATES_LIB)/Makefile.lib 40 | include $(INMATES_LIB)/../arm-common/Makefile.lib 41 | 42 | always := lib.a inmate.lds 43 | 44 | lib-y := $(common-objs-y) 45 | lib-y += header.o 46 | -------------------------------------------------------------------------------- /configs/arm64/miriac-sbc-ls1046a-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Demo inmate for Microsys miriac SBC-LS1046A board 5 | * 6 | * Copyright (c) Linutronix GmbH, 2019 7 | * 8 | * Authors: 9 | * Andreas Messerschmid 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | .num_irqchips = 0, 33 | .num_pci_devices = 0, 34 | 35 | .console = { 36 | .address = 0x21c0500, 37 | .type = JAILHOUSE_CON_TYPE_8250, 38 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 39 | JAILHOUSE_CON_REGDIST_1, 40 | }, 41 | }, 42 | 43 | .cpus = { 44 | 0x8, 45 | }, 46 | 47 | .mem_regions = { 48 | /* DUART1 */ 49 | { 50 | .phys_start = 0x21c0000, 51 | .virt_start = 0x21c0000, 52 | .size = 0x1000, 53 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 54 | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, 55 | }, 56 | /* RAM */ 57 | { 58 | .phys_start = 0xc0400000, 59 | .virt_start = 0, 60 | .size = 0x00010000, 61 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 62 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 63 | }, 64 | /* communication region */ { 65 | .virt_start = 0x80000000, 66 | .size = 0x00001000, 67 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 68 | JAILHOUSE_MEM_COMM_REGION, 69 | }, 70 | } 71 | }; 72 | -------------------------------------------------------------------------------- /inmates/tools/x86/linux-loader.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2015 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | 15 | struct boot_params { 16 | u8 padding1[0x230]; 17 | u32 kernel_alignment; 18 | u8 padding2[0x250 - 0x230 - 4]; 19 | u64 setup_data; 20 | u8 padding3[8]; 21 | u32 init_size; 22 | } __attribute__((packed)); 23 | 24 | struct setup_data { 25 | u64 next; 26 | u32 type; 27 | u32 length; 28 | u16 version; 29 | u16 compatible_version; 30 | u16 pm_timer_address; 31 | u16 num_cpus; 32 | u64 pci_mmconfig_base; 33 | u32 tsc_khz; 34 | u32 apic_khz; 35 | u8 standard_ioapic; 36 | u8 cpu_ids[SMP_MAX_CPUS]; 37 | /* Flags bits 0-3: has access to platform UART n */ 38 | u32 flags; 39 | } __attribute__((packed)); 40 | 41 | /* We use the cmdline section for zero page and setup data. */ 42 | static union { 43 | struct boot_params params; 44 | char __reservation[PAGE_SIZE * 3]; 45 | } boot __attribute__((section(".cmdline"))); 46 | 47 | void inmate_main(void) 48 | { 49 | void (*entry)(int, struct boot_params *); 50 | struct setup_data *setup_data; 51 | void *kernel; 52 | 53 | kernel = (void *)(unsigned long)boot.params.kernel_alignment; 54 | 55 | map_range(kernel, boot.params.init_size, MAP_CACHED); 56 | 57 | setup_data = (struct setup_data *)boot.params.setup_data; 58 | setup_data->pm_timer_address = comm_region->pm_timer_address; 59 | setup_data->pci_mmconfig_base = comm_region->pci_mmconfig_base; 60 | setup_data->tsc_khz = comm_region->tsc_khz; 61 | setup_data->apic_khz = comm_region->apic_khz; 62 | setup_data->num_cpus = comm_region->num_cpus; 63 | 64 | smp_wait_for_all_cpus(); 65 | memcpy(setup_data->cpu_ids, smp_cpu_ids, SMP_MAX_CPUS); 66 | 67 | entry = kernel + 0x200; 68 | entry(0, &boot.params); 69 | } 70 | -------------------------------------------------------------------------------- /configs/arm/emtrion-rzg1h-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on emCON-RZ/G1H: 5 | * 1 CPU, 64K RAM, serial ports SCIFA0, CCU 6 | * 7 | * Copyright (c) emtrion GmbH, 2017 8 | * 9 | * Authors: 10 | * Jan von Wiarda 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "emtrion-emconrzg1h-inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | 33 | .console = { 34 | .address = 0xe6c40000, 35 | .clock_reg = 0xe6150138, 36 | .gate_nr = 4, 37 | .divider = 0x1b, 38 | .type = JAILHOUSE_CON_TYPE_SCIFA, 39 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 40 | JAILHOUSE_CON_REGDIST_4, 41 | }, 42 | }, 43 | 44 | .cpus = { 45 | 0x2, 46 | }, 47 | 48 | .mem_regions = { 49 | /* SCIFA0 */ { 50 | .phys_start = 0xe6c40000, 51 | .virt_start = 0xe6c40000, 52 | .size = 0x1000, 53 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 54 | JAILHOUSE_MEM_IO, 55 | }, 56 | /* RAM */ { 57 | .phys_start = 0x7bff0000, 58 | .virt_start = 0, 59 | .size = 0x00010000, 60 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 61 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 62 | }, 63 | /* communication region */ { 64 | .virt_start = 0x80000000, 65 | .size = 0x00001000, 66 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 67 | JAILHOUSE_MEM_COMM_REGION, 68 | }, 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /configs/arm/emtrion-rzg1m-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on emCON-RZ/G1M: 5 | * 1 CPU, 64K RAM, serial ports SCIF4, CCU 6 | * 7 | * Copyright (c) emtrion GmbH, 2017 8 | * 9 | * Authors: 10 | * Jan von Wiarda 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "emtrion-emconrzg1m-inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | 33 | .console = { 34 | .address = 0xe6ee0000, 35 | .clock_reg = 0xe615014c, 36 | .gate_nr = 15, 37 | .divider = 0x10, 38 | .type = JAILHOUSE_CON_TYPE_HSCIF, 39 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 40 | JAILHOUSE_CON_REGDIST_4, 41 | }, 42 | }, 43 | 44 | .cpus = { 45 | 0x2, 46 | }, 47 | 48 | .mem_regions = { 49 | /* SCIF4 */ { 50 | .phys_start = 0xe6ee0000, 51 | .virt_start = 0xe6ee0000, 52 | .size = 0x1000, 53 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 54 | JAILHOUSE_MEM_IO, 55 | }, 56 | /* RAM */ { 57 | .phys_start = 0x7bff0000, 58 | .virt_start = 0, 59 | .size = 0x00010000, 60 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 61 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 62 | }, 63 | /* communication region */ { 64 | .virt_start = 0x80000000, 65 | .size = 0x00001000, 66 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 67 | JAILHOUSE_MEM_COMM_REGION, 68 | }, 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /configs/arm64/amd-seattle-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on AMD Seattle: 5 | * 1 CPU, 64K RAM, 1 serial port 6 | * 7 | * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH 8 | * 9 | * Authors: 10 | * Antonios Motakis 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | .num_irqchips = 0, 33 | .num_pci_devices = 0, 34 | 35 | .console = { 36 | .address = 0xe1010000, 37 | .type = JAILHOUSE_CON_TYPE_PL011, 38 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 39 | JAILHOUSE_CON_REGDIST_4, 40 | }, 41 | }, 42 | 43 | .cpus = { 44 | 0x10, 45 | }, 46 | 47 | .mem_regions = { 48 | /* UART */ { 49 | .phys_start = 0xe1010000, 50 | .virt_start = 0xe1010000, 51 | .size = 0x10000, 52 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 53 | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, 54 | }, 55 | /* RAM */ { 56 | .phys_start = 0x83b0000000, 57 | .virt_start = 0, 58 | .size = 0x00010000, 59 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 60 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 61 | }, 62 | /* communication region */ { 63 | .virt_start = 0x80000000, 64 | .size = 0x00001000, 65 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 66 | JAILHOUSE_MEM_COMM_REGION, 67 | }, 68 | } 69 | }; 70 | -------------------------------------------------------------------------------- /inmates/lib/x86/uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) OTH Regensburg, 2018 5 | * 6 | * Authors: 7 | * Ralf Ramsauer 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * Alternatively, you can use or redistribute this file under the following 13 | * BSD license: 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 19 | * 1. Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 36 | * THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | #include 41 | 42 | DECLARE_UART(8250); 43 | 44 | struct uart_chip *uart_array[] = { 45 | &UART_OPS_NAME(8250), 46 | NULL 47 | }; 48 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/ivshmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2016-2019 5 | * 6 | * Author: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | void arch_ivshmem_trigger_interrupt(struct ivshmem_endpoint *ive, 17 | unsigned int vector) 18 | { 19 | unsigned int irq_id = ive->irq_cache.id[vector]; 20 | 21 | if (irq_id) { 22 | /* 23 | * Ensure that all data written by the sending guest is visible 24 | * to the target before triggering the interrupt. 25 | */ 26 | memory_barrier(); 27 | 28 | irqchip_trigger_external_irq(irq_id); 29 | } 30 | } 31 | 32 | int arch_ivshmem_update_msix(struct ivshmem_endpoint *ive, unsigned int vector, 33 | bool enabled) 34 | { 35 | struct pci_device *device = ive->device; 36 | unsigned int irq_id = 0; 37 | 38 | if (enabled) { 39 | /* FIXME: validate MSI-X target address */ 40 | irq_id = device->msix_vectors[vector].data; 41 | if (irq_id < 32 || !irqchip_irq_in_cell(device->cell, irq_id)) 42 | return -EPERM; 43 | } 44 | 45 | /* 46 | * Lock used as barrier, ensuring all interrupts triggered after return 47 | * use the new setting. 48 | */ 49 | spin_lock(&ive->irq_lock); 50 | ive->irq_cache.id[vector] = irq_id; 51 | spin_unlock(&ive->irq_lock); 52 | 53 | return 0; 54 | } 55 | 56 | void arch_ivshmem_update_intx(struct ivshmem_endpoint *ive, bool enabled) 57 | { 58 | u8 pin = ive->cspace[PCI_CFG_INT/4] >> 8; 59 | struct pci_device *device = ive->device; 60 | 61 | /* 62 | * Lock used as barrier, ensuring all interrupts triggered after return 63 | * use the new setting. 64 | */ 65 | spin_lock(&ive->irq_lock); 66 | ive->irq_cache.id[0] = enabled ? 67 | (32 + device->cell->config->vpci_irq_base + pin - 1) : 0; 68 | spin_unlock(&ive->irq_lock); 69 | } 70 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/uart-scifa.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) emtrion GmbH, 2018 5 | * 6 | * Authors: 7 | * Ruediger Fichter 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #define SCIFA_SCABRR 0x04 18 | #define SCIFA_SCASCR 0x08 19 | #define SCIFA_SCASSR 0x14 20 | #define SCIFA_SCAFCR 0x18 21 | #define SCIFA_SCAFTDR 0x20 22 | 23 | #define SCIFA_SCASCR_RE 0x0010 24 | #define SCIFA_SCASCR_TE 0x0020 25 | 26 | #define SCIFA_SCASSR_TDFE 0x0020 27 | #define SCIFA_SCASSR_TEND 0x0040 28 | 29 | #define SCIFA_FIFO_SIZE 64 30 | #define SCIFA_TTRG_32BYTES 0 31 | 32 | static void uart_init(struct uart_chip *chip) 33 | { 34 | u16 scascr; 35 | 36 | if (chip->debug_console->divider) { 37 | scascr = mmio_read16(chip->virt_base + SCIFA_SCASCR); 38 | mmio_write16(chip->virt_base + SCIFA_SCASCR, 39 | scascr & ~(SCIFA_SCASCR_TE | SCIFA_SCASCR_RE)); 40 | mmio_write8(chip->virt_base + SCIFA_SCABRR, 41 | chip->debug_console->divider); 42 | mmio_write16(chip->virt_base + SCIFA_SCAFCR, 43 | SCIFA_TTRG_32BYTES); 44 | mmio_write16(chip->virt_base + SCIFA_SCASCR, 45 | scascr | SCIFA_SCASCR_TE); 46 | } 47 | } 48 | 49 | static bool uart_is_busy(struct uart_chip *chip) 50 | { 51 | return !(mmio_read16(chip->virt_base + SCIFA_SCASSR) & 52 | SCIFA_SCASSR_TDFE); 53 | } 54 | 55 | static void uart_write_char(struct uart_chip *chip, char c) 56 | { 57 | mmio_write8(chip->virt_base + SCIFA_SCAFTDR, c); 58 | mmio_write16(chip->virt_base + SCIFA_SCASSR, 59 | mmio_read16(chip->virt_base + SCIFA_SCASSR) & 60 | ~(SCIFA_SCASSR_TDFE | SCIFA_SCASSR_TEND)); 61 | } 62 | 63 | struct uart_chip uart_scifa_ops = { 64 | .init = uart_init, 65 | .is_busy = uart_is_busy, 66 | .write_char = uart_write_char, 67 | }; 68 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/cell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * Copyright (c) Valentine Sinitsyn, 2014 6 | * 7 | * Authors: 8 | * Jan Kiszka 9 | * Valentine Sinitsyn 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #ifndef _JAILHOUSE_ASM_CELL_H 16 | #define _JAILHOUSE_ASM_CELL_H 17 | 18 | #include 19 | 20 | struct cell_ioapic; 21 | 22 | /** x86-specific cell states. */ 23 | struct arch_cell { 24 | /** Buffer for the EPT/NPT root-level page table. */ 25 | u8 __attribute__((aligned(PAGE_SIZE))) root_table_page[PAGE_SIZE]; 26 | 27 | bool pio_i8042_allowed; 28 | 29 | /* Intel: PIO access bitmap. 30 | * AMD: I/O Permissions Map. */ 31 | u8 *io_bitmap; 32 | union { 33 | struct { 34 | /** Paging structures used for cell CPUs. */ 35 | struct paging_structures ept_structs; 36 | } vmx; /**< Intel VMX-specific fields. */ 37 | struct { 38 | /** Paging structures used for cell CPUs and IOMMU. */ 39 | struct paging_structures npt_iommu_structs; 40 | } svm; /**< AMD SVM-specific fields. */ 41 | }; 42 | 43 | union { 44 | struct { 45 | /** Paging structures used for DMA requests. */ 46 | struct paging_structures pg_structs; 47 | /** True if interrupt remapping support is emulated for this 48 | * cell. */ 49 | bool ir_emulation; 50 | } vtd; /**< Intel VT-d specific fields. */ 51 | }; 52 | 53 | /** Shadow value of PCI config space address port register. */ 54 | u32 pci_addr_port_val; 55 | 56 | /** List of IOAPICs assigned to this cell. */ 57 | struct cell_ioapic *ioapics; 58 | /** Number of assigned IOAPICs. */ 59 | unsigned int num_ioapics; 60 | 61 | /** Class Of Service for cache allocation (Intel only). */ 62 | u32 cos; 63 | /** Allocated L3 cache region (Intel only). */ 64 | u64 cat_mask; 65 | }; 66 | 67 | #endif /* !_JAILHOUSE_ASM_CELL_H */ 68 | -------------------------------------------------------------------------------- /inmates/demos/arm/gic-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * Copyright (c) Siemens AG, 2014-2017 6 | * 7 | * Authors: 8 | * Jean-Philippe Brucker 9 | * Jan Kiszka 10 | * 11 | * This work is licensed under the terms of the GNU GPL, version 2. See 12 | * the COPYING file in the top-level directory. 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #define BEATS_PER_SEC 10 19 | 20 | static u64 ticks_per_beat; 21 | static volatile u64 expected_ticks; 22 | 23 | /* 24 | * Enables blinking LED 25 | * Banana Pi: register 0x1c2090c, pin 24 26 | * Orange Pi Zero: register 0x1c20810, pin 17 27 | */ 28 | static void *led_reg; 29 | static unsigned int led_pin; 30 | 31 | static void handle_IRQ(unsigned int irqn) 32 | { 33 | static u64 min_delta = ~0ULL, max_delta = 0; 34 | u64 delta; 35 | 36 | if (irqn != TIMER_IRQ) 37 | return; 38 | 39 | delta = timer_get_ticks() - expected_ticks; 40 | if (delta < min_delta) 41 | min_delta = delta; 42 | if (delta > max_delta) 43 | max_delta = delta; 44 | 45 | printk("Timer fired, jitter: %6ld ns, min: %6ld ns, max: %6ld ns\n", 46 | (long)timer_ticks_to_ns(delta), 47 | (long)timer_ticks_to_ns(min_delta), 48 | (long)timer_ticks_to_ns(max_delta)); 49 | 50 | if (led_reg) 51 | mmio_write32(led_reg, mmio_read32(led_reg) ^ (1 << led_pin)); 52 | 53 | expected_ticks = timer_get_ticks() + ticks_per_beat; 54 | timer_start(ticks_per_beat); 55 | } 56 | 57 | void inmate_main(void) 58 | { 59 | printk("Initializing the GIC...\n"); 60 | irq_init(handle_IRQ); 61 | irq_enable(TIMER_IRQ); 62 | 63 | printk("Initializing the timer...\n"); 64 | ticks_per_beat = timer_get_frequency() / BEATS_PER_SEC; 65 | expected_ticks = timer_get_ticks() + ticks_per_beat; 66 | timer_start(ticks_per_beat); 67 | 68 | led_reg = (void *)(unsigned long)cmdline_parse_int("led-reg", 0); 69 | led_pin = cmdline_parse_int("led-pin", 0); 70 | 71 | halt(); 72 | } 73 | -------------------------------------------------------------------------------- /configs/arm64/k3-am654-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on K3 based platforms. 5 | * 1CPU, 64K RAM, 1 serial port(MCU UART 0). 6 | * 7 | * Copyright (c) 2019 Texas Instruments Incorporated - http://www.ti.com/ 8 | * 9 | * Authors: 10 | * Nikhil Devshatwar 11 | * Lokesh Vutla 12 | * 13 | * This work is licensed under the terms of the GNU GPL, version 2. See 14 | * the COPYING file in the top-level directory. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | struct { 21 | struct jailhouse_cell_desc cell; 22 | __u64 cpus[1]; 23 | struct jailhouse_memory mem_regions[3]; 24 | } __attribute__((packed)) config = { 25 | .cell = { 26 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 27 | .revision = JAILHOUSE_CONFIG_REVISION, 28 | .name = "inmate-demo", 29 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 30 | 31 | .cpu_set_size = sizeof(config.cpus), 32 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 33 | .num_irqchips = 0, 34 | .num_pci_devices = 0, 35 | 36 | .console = { 37 | .address = 0x40a00000, 38 | .divider = 0x35, 39 | .type = JAILHOUSE_CON_TYPE_8250, 40 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 41 | JAILHOUSE_CON_REGDIST_4, 42 | }, 43 | }, 44 | 45 | .cpus = { 46 | 0x4, 47 | }, 48 | 49 | .mem_regions = { 50 | /* MCU UART0 */ { 51 | .phys_start = 0x40a00000, 52 | .virt_start = 0x40a00000, 53 | .size = 0x10000, 54 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 55 | JAILHOUSE_MEM_IO, 56 | }, 57 | /* RAM */ { 58 | .phys_start = 0x8e0000000, 59 | .virt_start = 0, 60 | .size = 0x00010000, 61 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 62 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 63 | }, 64 | /* communication region */ { 65 | .virt_start = 0x80000000, 66 | .size = 0x00001000, 67 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 68 | JAILHOUSE_MEM_COMM_REGION, 69 | }, 70 | } 71 | }; 72 | -------------------------------------------------------------------------------- /scripts/include.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Jailhouse, a Linux-based partitioning hypervisor 3 | # 4 | # Copyright (c) Siemens AG, 2014 5 | # 6 | # Authors: 7 | # Jan Kiszka 8 | # Benjamin Block 9 | # 10 | # This work is licensed under the terms of the GNU GPL, version 2. See 11 | # the COPYING file in the top-level directory. 12 | # 13 | 14 | ifeq ($(V),1) 15 | Q = 16 | else 17 | Q = @ 18 | endif 19 | 20 | MAKEFLAGS += --no-print-directory 21 | 22 | prefix ?= /usr/local 23 | exec_prefix ?= $(prefix) 24 | sbindir ?= $(exec_prefix)/sbin 25 | libexecdir ?= $(exec_prefix)/libexec 26 | datarootdir ?= $(prefix)/share 27 | datadir ?= $(datarootdir) 28 | man8dir ?= $(datarootdir)/man/man8 29 | completionsdir ?= /usr/share/bash-completion/completions 30 | firmwaredir ?= /lib/firmware 31 | 32 | # all directories listed here will be created using a generic rule below 33 | INSTALL_DIRECTORIES := $(sbindir) \ 34 | $(libexecdir) \ 35 | $(datadir) \ 36 | $(man8dir) \ 37 | $(completionsdir) \ 38 | $(firmwaredir) 39 | 40 | INSTALL ?= install 41 | INSTALL_PROGRAM ?= $(INSTALL) 42 | INSTALL_DATA ?= $(INSTALL) -m 644 43 | INSTALL_DIR ?= $(INSTALL) -d -m 755 44 | 45 | PYTHON ?= python 46 | PIP := $(PYTHON) -m pip 47 | 48 | ifeq ($(strip $(shell $(PIP) > /dev/null 2> /dev/null && echo "y")), y) 49 | PYTHON_PIP_USABLE := yes 50 | endif 51 | 52 | # creates a rule for each dir in $(INSTALL_DIRECTORIES) under the current 53 | # $(DESTDIR) and additionally to that for each of these dirs a subdir named 54 | # `jailhouse`. These can be used as prerequirement for install-rules and will 55 | # thus be created on demand (or not at all if not used in that way). 56 | $(sort $(INSTALL_DIRECTORIES:%=$(DESTDIR)%) \ 57 | $(INSTALL_DIRECTORIES:%=$(DESTDIR)%/jailhouse)): 58 | $(INSTALL_DIR) $@ 59 | 60 | ARCH ?= $(shell uname -m) 61 | ifeq ($(ARCH),x86_64) 62 | override ARCH = x86 63 | endif 64 | ifeq ($(ARCH),armv7l) 65 | override ARCH = arm 66 | endif 67 | ifeq ($(ARCH),aarch64) 68 | override ARCH = arm64 69 | endif 70 | -------------------------------------------------------------------------------- /hypervisor/arch/arm/include/asm/spinlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * Copied from arch/arm/include/asm/spinlock.h in Linux 13 | */ 14 | #ifndef _JAILHOUSE_ASM_SPINLOCK_H 15 | #define _JAILHOUSE_ASM_SPINLOCK_H 16 | 17 | #include 18 | 19 | #ifndef __ASSEMBLY__ 20 | 21 | #define TICKET_SHIFT 16 22 | 23 | typedef struct { 24 | union { 25 | u32 slock; 26 | struct __raw_tickets { 27 | u16 owner; 28 | u16 next; 29 | } tickets; 30 | }; 31 | } spinlock_t; 32 | 33 | static inline void spin_lock(spinlock_t *lock) 34 | { 35 | unsigned long tmp; 36 | u32 newval; 37 | spinlock_t lockval; 38 | 39 | /* Take the lock by updating the high part atomically */ 40 | asm volatile ( 41 | ".arch_extension mp\n\t" 42 | "pldw [%3]\n\t" 43 | "1:\n\t" 44 | "ldrex %0, [%3]\n\t" 45 | "add %1, %0, %4\n\t" 46 | "strex %2, %1, [%3]\n\t" 47 | "teq %2, #0\n\t" 48 | "bne 1b\n\t" 49 | : "=&r" (lockval), "=&r" (newval), "=&r" (tmp) 50 | : "r" (&lock->slock), "I" (1 << TICKET_SHIFT) 51 | : "cc"); 52 | 53 | while (lockval.tickets.next != lockval.tickets.owner) 54 | asm volatile ( 55 | "wfe\n\t" 56 | "ldrh %0, [%1]\n\t" 57 | : "=r" (lockval.tickets.owner) 58 | : "r" (&lock->tickets.owner)); 59 | 60 | /* Ensure we have the lock before doing any more memory ops */ 61 | dmb(ish); 62 | } 63 | 64 | static inline void spin_unlock(spinlock_t *lock) 65 | { 66 | /* Ensure all memory ops are finished before releasing the lock */ 67 | dmb(ish); 68 | 69 | /* No need for an exclusive, since only one CPU can unlock at a time. */ 70 | lock->tickets.owner++; 71 | 72 | /* Ensure the spinlock is updated before notifying other CPUs */ 73 | dsb(ishst); 74 | asm volatile("sev"); 75 | } 76 | 77 | #endif /* !__ASSEMBLY__ */ 78 | #endif /* !_JAILHOUSE_ASM_SPINLOCK_H */ 79 | -------------------------------------------------------------------------------- /configs/arm/emtrion-rzg1e-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on emCON-RZ/G1E: 5 | * 1 CPU, 64K RAM, serial ports SCIF4, CCU 6 | * 7 | * Copyright (c) emtrion GmbH, 2017 8 | * 9 | * Authors: 10 | * Ruediger Fichter 11 | * 12 | * This work is licensed under the terms of the GNU GPL, version 2. See 13 | * the COPYING file in the top-level directory. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | struct { 20 | struct jailhouse_cell_desc cell; 21 | __u64 cpus[1]; 22 | struct jailhouse_memory mem_regions[3]; 23 | } __attribute__((packed)) config = { 24 | .cell = { 25 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 26 | .revision = JAILHOUSE_CONFIG_REVISION, 27 | .name = "emtrion-emconrzg1e-inmate-demo", 28 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 29 | 30 | .cpu_set_size = sizeof(config.cpus), 31 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 32 | 33 | .console = { 34 | .address = 0xe6ee0000, 35 | .clock_reg = 0xe615014c, 36 | .gate_nr = 15, 37 | .divider = 0x10, 38 | .type = JAILHOUSE_CON_TYPE_HSCIF, 39 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 40 | JAILHOUSE_CON_REGDIST_4, 41 | }, 42 | }, 43 | 44 | .cpus = { 45 | 0x2, 46 | }, 47 | 48 | .mem_regions = { 49 | /* SCIF4 */ { 50 | .phys_start = 0xe6ee0000, 51 | .virt_start = 0xe6ee0000, 52 | .size = 0x400, 53 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 54 | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_IO_8 | 55 | JAILHOUSE_MEM_IO_16 | JAILHOUSE_MEM_IO_32, 56 | }, 57 | /* RAM */ { 58 | .phys_start = 0x7bff0000, 59 | .virt_start = 0, 60 | .size = 0x00010000, 61 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 62 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 63 | }, 64 | /* communication region */ { 65 | .virt_start = 0x80000000, 66 | .size = 0x00001000, 67 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 68 | JAILHOUSE_MEM_COMM_REGION, 69 | }, 70 | } 71 | }; 72 | -------------------------------------------------------------------------------- /Documentation/sysfs-entries.txt: -------------------------------------------------------------------------------- 1 | Sysfs Entries 2 | ============= 3 | 4 | The following sysfs entries are provided by the Jailhouse Linux driver. These 5 | can be used for monitoring the state of the hypervisor and its cells. 6 | 7 | /sys/devices/jailhouse 8 | |- console - hypervisor console (see [1]) 9 | |- enabled - 1 if Jailhouse is enabled, 0 otherwise 10 | |- mem_pool_size - number of pages in hypervisor memory pool 11 | |- mem_pool_used - used pages of hypervisor memory pool 12 | |- remap_pool_size - number of pages in hypervisor remapping pool 13 | |- remap_pool_used - used pages of hypervisor remapping pool 14 | `- cells 15 | |- - unique numerical ID 16 | | |- name - cell name 17 | | |- state - "running", "running/locked", "shut down", or 18 | | | "failed" 19 | | |- cpus_assigned - bitmask of assigned logical CPUs 20 | | |- cpus_assigned_list - human readable list of assigned logical CPUs 21 | | |- cpus_failed - bitmask of logical CPUs that caused a failure 22 | | |- cpus_failed_list - human readable list of logical CPUs that 23 | | | caused a failure 24 | | `- statistics 25 | | |- cpu 26 | | | |- vmexits_total - Total number of VM exits on CPU 27 | | | `- vmexits_ - VM exits due to on CPU 28 | | |- vmexits_total - Total number of VM exits on all cell CPUs 29 | | `- vmexits_ - VM exits due to on all cell CPUs 30 | `- ... 31 | 32 | Note that accumulated statistics over all CPUs of a cell are not collected 33 | atomically and may not reflect a fully consistent state. The existence and 34 | semantics of VM exit reason values are architecture-dependent and may change in 35 | future versions. In general statistics shall only be considered as a first hint 36 | when analyzing cell behavior. 37 | 38 | [1] Documentation/debug-output.md 39 | -------------------------------------------------------------------------------- /configs/arm64/k3-j721e-evm-inmate-demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Configuration for demo inmate on K3 based platforms. 5 | * 1CPU, 64K RAM, 1 serial port. 6 | * 7 | * Copyright (c) 2019 Texas Instruments Incorporated - http://www.ti.com/ 8 | * 9 | * Authors: 10 | * Nikhil Devshatwar 11 | * Lokesh Vutla 12 | * 13 | * This work is licensed under the terms of the GNU GPL, version 2. See 14 | * the COPYING file in the top-level directory. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | struct { 21 | struct jailhouse_cell_desc cell; 22 | __u64 cpus[1]; 23 | struct jailhouse_memory mem_regions[3]; 24 | } __attribute__((packed)) config = { 25 | .cell = { 26 | .signature = JAILHOUSE_CELL_DESC_SIGNATURE, 27 | .revision = JAILHOUSE_CONFIG_REVISION, 28 | .name = "inmate-demo", 29 | .flags = JAILHOUSE_CELL_PASSIVE_COMMREG, 30 | 31 | .cpu_set_size = sizeof(config.cpus), 32 | .num_memory_regions = ARRAY_SIZE(config.mem_regions), 33 | .num_irqchips = 0, 34 | .num_pci_devices = 0, 35 | 36 | .console = { 37 | .address = 0x02810000, 38 | .divider = 0x1b, 39 | .type = JAILHOUSE_CON_TYPE_8250, 40 | .flags = JAILHOUSE_CON_ACCESS_MMIO | 41 | JAILHOUSE_CON_MDR_QUIRK | 42 | JAILHOUSE_CON_REGDIST_4, 43 | }, 44 | }, 45 | 46 | .cpus = { 47 | 0x2, 48 | }, 49 | 50 | .mem_regions = { 51 | /* main_uart1 */ { 52 | .phys_start = 0x02810000, 53 | .virt_start = 0x02810000, 54 | .size = 0x10000, 55 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 56 | JAILHOUSE_MEM_IO, 57 | }, 58 | /* RAM */ { 59 | .phys_start = 0x89ff00000, 60 | .virt_start = 0, 61 | .size = 0x00010000, 62 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 63 | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, 64 | }, 65 | /* communication region */ { 66 | .virt_start = 0x80000000, 67 | .size = 0x00001000, 68 | .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | 69 | JAILHOUSE_MEM_COMM_REGION, 70 | }, 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /hypervisor/arch/arm-common/include/asm/gic_v2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) ARM Limited, 2014 5 | * 6 | * Authors: 7 | * Jean-Philippe Brucker 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | */ 12 | 13 | #ifndef _JAILHOUSE_ASM_GIC_V2_H 14 | #define _JAILHOUSE_ASM_GIC_V2_H 15 | 16 | #define GICC_SIZE 0x2000 17 | #define GICH_SIZE 0x2000 18 | 19 | #define GICDv2_CIDR0 0xff0 20 | #define GICDv2_PIDR0 0xfe0 21 | #define GICDv2_PIDR2 0xfe8 22 | #define GICDv2_PIDR4 0xfd0 23 | 24 | #define GICC_CTLR 0x0000 25 | #define GICC_PMR 0x0004 26 | #define GICC_IAR 0x000c 27 | #define GICC_EOIR 0x0010 28 | #define GICC_DIR 0x1000 29 | 30 | #define GICC_CTLR_GRPEN1 (1 << 0) 31 | #define GICC_CTLR_EOImode (1 << 9) 32 | 33 | #define GICC_PMR_DEFAULT 0xf0 34 | 35 | #define GICH_HCR 0x000 36 | #define GICH_VTR 0x004 37 | #define GICH_VMCR 0x008 38 | #define GICH_ELSR0 0x030 39 | #define GICH_ELSR1 0x034 40 | #define GICH_APR 0x0f0 41 | #define GICH_LR_BASE 0x100 42 | 43 | #define GICV_PMR_SHIFT 3 44 | #define GICH_VMCR_PMR_SHIFT 27 45 | #define GICH_VMCR_EN0 (1 << 0) 46 | #define GICH_VMCR_EN1 (1 << 1) 47 | #define GICH_VMCR_ACKCtl (1 << 2) 48 | #define GICH_VMCR_EOImode (1 << 9) 49 | 50 | #define GICH_HCR_EN (1 << 0) 51 | #define GICH_HCR_UIE (1 << 1) 52 | #define GICH_HCR_LRENPIE (1 << 2) 53 | #define GICH_HCR_NPIE (1 << 3) 54 | #define GICH_HCR_VGRP0EIE (1 << 4) 55 | #define GICH_HCR_VGRP0DIE (1 << 5) 56 | #define GICH_HCR_VGRP1EIE (1 << 6) 57 | #define GICH_HCR_VGRP1DIE (1 << 7) 58 | #define GICH_HCR_EOICOUNT_SHIFT 27 59 | 60 | #define GICH_LR_HW_BIT (1 << 31) 61 | #define GICH_LR_GRP1_BIT (1 << 30) 62 | #define GICH_LR_ACTIVE_BIT (1 << 29) 63 | #define GICH_LR_PENDING_BIT (1 << 28) 64 | #define GICH_LR_PRIORITY_SHIFT 23 65 | #define GICH_LR_SGI_EOI_BIT (1 << 19) 66 | #define GICH_LR_CPUID_SHIFT 10 67 | #define GICH_LR_PHYS_ID_SHIFT 10 68 | #define GICH_LR_VIRT_ID_MASK 0x3ff 69 | #endif /* _JAILHOUSE_ASM_GIC_V2_H */ 70 | -------------------------------------------------------------------------------- /hypervisor/arch/x86/include/asm/bitops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2013 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * This file is based on linux/arch/x86/include/asm/bitops.h: 13 | * 14 | * Copyright 1992, Linus Torvalds. 15 | * Copyright (c) Linux kernel developers, 2013 16 | */ 17 | 18 | #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1) 19 | /* Technically wrong, but this avoids compilation errors on some gcc 20 | versions. */ 21 | #define BITOP_ADDR(x) "=m" (*(volatile long *) (x)) 22 | #else 23 | #define BITOP_ADDR(x) "+m" (*(volatile long *) (x)) 24 | #endif 25 | 26 | static inline __attribute__((always_inline)) int 27 | constant_test_bit(unsigned int nr, const volatile unsigned long *addr) 28 | { 29 | return ((1UL << (nr % BITS_PER_LONG)) & 30 | (addr[nr / BITS_PER_LONG])) != 0; 31 | } 32 | 33 | static inline int variable_test_bit(int nr, volatile const unsigned long *addr) 34 | { 35 | int oldbit; 36 | 37 | asm volatile("bt %2,%1\n\t" 38 | "sbb %0,%0" 39 | : "=r" (oldbit) 40 | : "m" (*(unsigned long *)addr), "Ir" (nr)); 41 | 42 | return oldbit; 43 | } 44 | 45 | #define test_bit(nr, addr) \ 46 | (__builtin_constant_p((nr)) \ 47 | ? constant_test_bit((nr), (addr)) \ 48 | : variable_test_bit((nr), (addr))) 49 | 50 | static inline int atomic_test_and_set_bit(int nr, volatile unsigned long *addr) 51 | { 52 | int oldbit; 53 | 54 | asm volatile("lock bts %2,%1\n\t" 55 | "sbb %0,%0" : "=r" (oldbit), BITOP_ADDR(addr) 56 | : "Ir" (nr) : "memory"); 57 | 58 | return oldbit; 59 | } 60 | 61 | static inline unsigned long ffzl(unsigned long word) 62 | { 63 | asm("rep; bsf %1,%0" 64 | : "=r" (word) 65 | : "r" (~word)); 66 | return word; 67 | } 68 | 69 | static inline unsigned long ffsl(unsigned long word) 70 | { 71 | asm("rep; bsf %1,%0" 72 | : "=r" (word) 73 | : "rm" (word)); 74 | return word; 75 | } 76 | -------------------------------------------------------------------------------- /inmates/lib/alloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Jailhouse, a Linux-based partitioning hypervisor 3 | * 4 | * Copyright (c) Siemens AG, 2018 5 | * 6 | * Authors: 7 | * Jan Kiszka 8 | * 9 | * This work is licensed under the terms of the GNU GPL, version 2. See 10 | * the COPYING file in the top-level directory. 11 | * 12 | * Alternatively, you can use or redistribute this file under the following 13 | * BSD license: 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 19 | * 1. Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice, this list of conditions and the following disclaimer in the 24 | * documentation and/or other materials provided with the distribution. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 36 | * THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | 41 | unsigned long heap_pos = (unsigned long)stack_top; 42 | 43 | void *alloc(unsigned long size, unsigned long align) 44 | { 45 | unsigned long base = (heap_pos + align - 1) & ~(align - 1); 46 | 47 | heap_pos = base + size; 48 | return (void *)base; 49 | } 50 | --------------------------------------------------------------------------------