diff --git a/doc/developer-guides/hld/hv-vcat.rst b/doc/developer-guides/hld/hv-vcat.rst index 3602cb09d..3f7159945 100644 --- a/doc/developer-guides/hld/hv-vcat.rst +++ b/doc/developer-guides/hld/hv-vcat.rst @@ -105,19 +105,19 @@ the following actions: mask_shift = ffs64(max_pcbm) vcosid = vmsr - MSR_IA32_type_MASK_0 - pcosid = vm_config->pclosids[vcosid] + pcosid = vm_config->arch.pclosids[vcosid] pmsr = MSR_IA32_type_MASK_0 + pcosid pcbm = vcbm << mask_shift vcbm = pcbm >> mask_shift Where - ``vm_config->pclosids[]``: array of physical COS IDs, where each corresponds to one ``vcpu_clos`` that + ``vm_config->arch.pclosids[]``: array of physical COS IDs, where each corresponds to one ``vcpu_clos`` that is defined in the scenario file ``max_pcbm``: a bitmask that selects all the physical cache ways assigned to the VM, corresponds to the nth ``CLOS_MASK`` that is defined in scenario file, where n = the first physical COS ID assigned - = ``vm_config->pclosids[0]`` + = ``vm_config->arch.pclosids[0]`` ``ffs64(max_pcbm)``: find the first (least significant) bit set in ``max_pcbm`` and return the index of that bit. diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 8a9713c4d..47785a423 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -168,6 +168,7 @@ COMMON_C_SRCS += lib/sprintf.c ifdef STACK_PROTECTOR COMMON_C_SRCS += lib/stack_protector.c endif +COMMON_C_SRCS += common/vm_config.c # dm componment COMMON_C_SRCS += dm/vuart.c diff --git a/hypervisor/arch/x86/Makefile b/hypervisor/arch/x86/Makefile index e36b61232..f83247e65 100644 --- a/hypervisor/arch/x86/Makefile +++ b/hypervisor/arch/x86/Makefile @@ -102,7 +102,6 @@ HW_C_SRCS += arch/x86/trampoline.c HW_S_SRCS += arch/x86/sched.S HW_C_SRCS += arch/x86/rdt.c HW_C_SRCS += arch/x86/sgx.c -HW_C_SRCS += arch/x86/configs/vm_config.c HW_C_SRCS += boot/acpi_base.c # ACPI parsing component # This part should be isolated from FuSa Cert diff --git a/hypervisor/arch/x86/configs/pci_dev.c b/hypervisor/arch/x86/configs/pci_dev.c index 0a1f4286d..3f463f9b9 100644 --- a/hypervisor/arch/x86/configs/pci_dev.c +++ b/hypervisor/arch/x86/configs/pci_dev.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include #include #include #include diff --git a/hypervisor/arch/x86/guest/optee.c b/hypervisor/arch/x86/guest/optee.c index 09b1f7965..a17585f68 100644 --- a/hypervisor/arch/x86/guest/optee.c +++ b/hypervisor/arch/x86/guest/optee.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/hypervisor/arch/x86/guest/vcat.c b/hypervisor/arch/x86/guest/vcat.c index 42a758860..6f1a0b39a 100644 --- a/hypervisor/arch/x86/guest/vcat.c +++ b/hypervisor/arch/x86/guest/vcat.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -53,12 +53,12 @@ uint16_t vcat_get_num_vclosids(const struct acrn_vm *vm) if (is_vcat_configured(vm)) { /* * For performance and simplicity, here number of vCLOSIDs (num_vclosids) is set - * equal to the number of pCLOSIDs assigned to this VM (get_vm_config(vm->vm_id)->num_pclosids). + * equal to the number of pCLOSIDs assigned to this VM (get_vm_config(vm->vm_id)->arch.num_pclosids). * But technically, we do not have to make such an assumption. For example, * Hypervisor could implement CLOSID context switch, then number of vCLOSIDs * can be greater than the number of pCLOSIDs assigned. etc. */ - num_vclosids = get_vm_config(vm->vm_id)->num_pclosids; + num_vclosids = get_vm_config(vm->vm_id)->arch.num_pclosids; } return num_vclosids; @@ -68,7 +68,7 @@ uint16_t vcat_get_num_vclosids(const struct acrn_vm *vm) * @brief Map vCLOSID to pCLOSID * * @pre vm != NULL && vm->vm_id < CONFIG_MAX_VM_NUM - * @pre (get_vm_config(vm->vm_id)->pclosids != NULL) && (vclosid < get_vm_config(vm->vm_id)->num_pclosids) + * @pre (get_vm_config(vm->vm_id)->arch.pclosids != NULL) && (vclosid < get_vm_config(vm->vm_id)->arch.num_pclosids) */ static uint16_t vclosid_to_pclosid(const struct acrn_vm *vm, uint16_t vclosid) { @@ -80,9 +80,9 @@ static uint16_t vclosid_to_pclosid(const struct acrn_vm *vm, uint16_t vclosid) * * Note that write_vcbm() calls vclosid_to_pclosid() indirectly, in write_vcbm(), * the is_l2_vcbm_msr()/is_l3_vcbm_msr() calls ensure that vclosid is always less than - * get_vm_config(vm->vm_id)->num_pclosids, so vclosid is always an array index within bound here + * get_vm_config(vm->vm_id)->arch.num_pclosids, so vclosid is always an array index within bound here */ - return get_vm_config(vm->vm_id)->pclosids[vclosid]; + return get_vm_config(vm->vm_id)->arch.pclosids[vclosid]; } /** @@ -126,9 +126,9 @@ static uint64_t get_max_pcbm(const struct acrn_vm *vm, int res) uint64_t max_pcbm = 0UL; if (is_l2_vcat_configured(vm) && (res == RDT_RESOURCE_L2)) { - max_pcbm = get_vm_config(vm->vm_id)->max_l2_pcbm; + max_pcbm = get_vm_config(vm->vm_id)->arch.max_l2_pcbm; } else if (is_l3_vcat_configured(vm) && (res == RDT_RESOURCE_L3)) { - max_pcbm = get_vm_config(vm->vm_id)->max_l3_pcbm; + max_pcbm = get_vm_config(vm->vm_id)->arch.max_l3_pcbm; } return max_pcbm; diff --git a/hypervisor/arch/x86/guest/vcpuid.c b/hypervisor/arch/x86/guest/vcpuid.c index 6f47c6c58..c9ef59363 100644 --- a/hypervisor/arch/x86/guest/vcpuid.c +++ b/hypervisor/arch/x86/guest/vcpuid.c @@ -385,7 +385,7 @@ static void guest_cpuid_04h(__unused struct acrn_vm *vm, uint32_t *eax, uint32_t #ifdef CONFIG_VCAT_ENABLED if (is_vcat_configured(vm)) { /* set_vcpuid_vcat_04h will not change entry.eax */ - result = set_vcpuid_vcat_04h(vm, &entry); + set_vcpuid_vcat_04h(vm, &entry); } #endif } diff --git a/hypervisor/arch/x86/guest/vmsr.c b/hypervisor/arch/x86/guest/vmsr.c index 3e9e77125..f6d4a199a 100644 --- a/hypervisor/arch/x86/guest/vmsr.c +++ b/hypervisor/arch/x86/guest/vmsr.c @@ -371,7 +371,7 @@ static void intercept_x2apic_msrs(uint8_t *msr_bitmap_arg, uint32_t mode) /** * @pre vcpu != NULL && vcpu->vm != NULL && vcpu->vm->vm_id < CONFIG_MAX_VM_NUM - * @pre (is_platform_rdt_capable() == false()) || (is_platform_rdt_capable() && get_vm_config(vcpu->vm->vm_id)->pclosids != NULL) + * @pre (is_platform_rdt_capable() == false()) || (is_platform_rdt_capable() && get_vm_config(vcpu->vm->vm_id)->arch.pclosids != NULL) */ static void prepare_auto_msr_area(struct acrn_vcpu *vcpu) { @@ -390,9 +390,9 @@ static void prepare_auto_msr_area(struct acrn_vcpu *vcpu) struct acrn_vm_config *cfg = get_vm_config(vcpu->vm->vm_id); uint16_t vcpu_clos; - ASSERT(cfg->pclosids != NULL, "error, cfg->pclosids is NULL"); + ASSERT(cfg->arch.pclosids != NULL, "error, cfg->arch.pclosids is NULL"); - vcpu_clos = cfg->pclosids[vcpu->vcpu_id%cfg->num_pclosids]; + vcpu_clos = cfg->arch.pclosids[vcpu->vcpu_id%cfg->arch.num_pclosids]; /* RDT: only load/restore MSR_IA32_PQR_ASSOC when hv and guest have different settings * vCAT: always load/restore MSR_IA32_PQR_ASSOC diff --git a/hypervisor/arch/x86/rdt.c b/hypervisor/arch/x86/rdt.c index 413469353..8fd5cf512 100644 --- a/hypervisor/arch/x86/rdt.c +++ b/hypervisor/arch/x86/rdt.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include const uint16_t hv_clos = 0U; diff --git a/hypervisor/arch/x86/sgx.c b/hypervisor/arch/x86/sgx.c index 028b7e2b9..9c4c0dc8f 100644 --- a/hypervisor/arch/x86/sgx.c +++ b/hypervisor/arch/x86/sgx.c @@ -59,7 +59,7 @@ static int32_t partition_epc(void) uint64_t psec_addr = 0UL, psec_size = 0UL; uint64_t free_size = 0UL, alloc_size; struct acrn_vm_config *vm_config = get_vm_config(vm_id); - uint64_t vm_request_size = vm_config->epc.size; + uint64_t vm_request_size = vm_config->arch.epc.size; int32_t ret = 0; while (psec_id < MAX_EPC_SECTIONS) { @@ -70,7 +70,7 @@ static int32_t partition_epc(void) } mid = 0U; vm_config = get_vm_config(vm_id); - vm_request_size = vm_config->epc.size; + vm_request_size = vm_config->arch.epc.size; } else { if (free_size == 0UL) { ret = get_epc_section(psec_id, &psec_addr, &psec_size); @@ -83,7 +83,7 @@ static int32_t partition_epc(void) alloc_size = min(vm_request_size, free_size); vm_epc_maps[mid][vm_id].size = alloc_size; vm_epc_maps[mid][vm_id].hpa = psec_addr + psec_size - free_size; - vm_epc_maps[mid][vm_id].gpa = vm_config->epc.base + vm_config->epc.size - vm_request_size; + vm_epc_maps[mid][vm_id].gpa = vm_config->arch.epc.base + vm_config->arch.epc.size - vm_request_size; vm_request_size -= alloc_size; free_size -= alloc_size; mid++; diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index 838cfda0e..660a82342 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/hypervisor/common/vcpu.c b/hypervisor/common/vcpu.c index 6bc5a39bc..31d9ce034 100644 --- a/hypervisor/common/vcpu.c +++ b/hypervisor/common/vcpu.c @@ -13,6 +13,8 @@ #include #include +#include + bool is_vcpu_bsp(const struct acrn_vcpu *vcpu) { return (vcpu->vcpu_id == BSP_CPU_ID); diff --git a/hypervisor/common/vm.c b/hypervisor/common/vm.c index 660811b75..1d3d209f3 100644 --- a/hypervisor/common/vm.c +++ b/hypervisor/common/vm.c @@ -10,6 +10,7 @@ #include #include #include +#include #include static struct acrn_vm vm_array[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE); diff --git a/hypervisor/arch/x86/configs/vm_config.c b/hypervisor/common/vm_config.c similarity index 96% rename from hypervisor/arch/x86/configs/vm_config.c rename to hypervisor/common/vm_config.c index 16d459b91..e4c377c9c 100644 --- a/hypervisor/arch/x86/configs/vm_config.c +++ b/hypervisor/common/vm_config.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include #include #include diff --git a/hypervisor/include/arch/riscv/asm/vm_config.h b/hypervisor/include/arch/riscv/asm/vm_config.h index cd84533fc..d1629d49b 100644 --- a/hypervisor/include/arch/riscv/asm/vm_config.h +++ b/hypervisor/include/arch/riscv/asm/vm_config.h @@ -7,25 +7,17 @@ * Haicheng Li */ -#ifndef VM_CONFIG_H_ -#define VM_CONFIG_H_ +#ifndef RISCV_VM_CONFIG_H_ +#define RISCV_VM_CONFIG_H_ #include #define MAX_VCPUS_PER_VM MAX_PCPU_NUM #define CONFIG_MAX_VM_NUM 16U -/* TODO: To be moved in later patches */ -enum os_kernel_type { - DUMMY, -}; +#define DM_OWNED_GUEST_FLAG_MASK 0UL + +struct arch_vm_config { -/* TODO: Dummy, to be removed */ -#include -struct acrn_vm_config { - struct sched_params sched_params; /* Scheduler params for vCPUs of this VM */ }; -static inline struct acrn_vm_config *get_vm_config(__unused uint16_t vm_id) { - return NULL; -} #endif /* VM_CONFIG_H_ */ diff --git a/hypervisor/include/arch/x86/asm/guest/nested.h b/hypervisor/include/arch/x86/asm/guest/nested.h index 11f058339..57e01ab56 100644 --- a/hypervisor/include/arch/x86/asm/guest/nested.h +++ b/hypervisor/include/arch/x86/asm/guest/nested.h @@ -6,7 +6,7 @@ #ifndef NESTED_H #define NESTED_H -#include +#include #include /* helper data structure to make VMX capability MSR manipulation easier */ diff --git a/hypervisor/include/arch/x86/asm/guest/optee.h b/hypervisor/include/arch/x86/asm/guest/optee.h index b9d9bdf38..09a75987c 100644 --- a/hypervisor/include/arch/x86/asm/guest/optee.h +++ b/hypervisor/include/arch/x86/asm/guest/optee.h @@ -8,7 +8,7 @@ #define TEE_H_ #include -#include +#include #include #define TEE_FIXED_NONSECURE_VECTOR 0x29U diff --git a/hypervisor/include/arch/x86/asm/guest/vcpu.h b/hypervisor/include/arch/x86/asm/guest/vcpu.h index ce7364f82..dd0963933 100644 --- a/hypervisor/include/arch/x86/asm/guest/vcpu.h +++ b/hypervisor/include/arch/x86/asm/guest/vcpu.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include /** * @brief vcpu diff --git a/hypervisor/include/arch/x86/asm/guest/vm.h b/hypervisor/include/arch/x86/asm/guest/vm.h index b01f3b3d6..b2bb12a92 100644 --- a/hypervisor/include/arch/x86/asm/guest/vm.h +++ b/hypervisor/include/arch/x86/asm/guest/vm.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #ifdef CONFIG_HYPERV_ENABLED diff --git a/hypervisor/include/arch/x86/asm/pci_dev.h b/hypervisor/include/arch/x86/asm/pci_dev.h index d4f8f8dd4..865514ab1 100644 --- a/hypervisor/include/arch/x86/asm/pci_dev.h +++ b/hypervisor/include/arch/x86/asm/pci_dev.h @@ -7,7 +7,7 @@ #ifndef PCI_DEV_H_ #define PCI_DEV_H_ -#include +#include extern struct acrn_vm_pci_dev_config sos_pci_devs[CONFIG_MAX_PCI_DEV_NUM]; diff --git a/hypervisor/include/arch/x86/asm/per_cpu.h b/hypervisor/include/arch/x86/asm/per_cpu.h index ce1f80f10..c8df136f5 100644 --- a/hypervisor/include/arch/x86/asm/per_cpu.h +++ b/hypervisor/include/arch/x86/asm/per_cpu.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include struct per_cpu_arch { /* vmxon_region MUST be 4KB-aligned */ diff --git a/hypervisor/include/arch/x86/asm/vm_config.h b/hypervisor/include/arch/x86/asm/vm_config.h index 60291cf10..999482f65 100644 --- a/hypervisor/include/arch/x86/asm/vm_config.h +++ b/hypervisor/include/arch/x86/asm/vm_config.h @@ -1,61 +1,14 @@ + /* - * Copyright (C) 2018-2022 Intel Corporation. + * Copyright (C) 2018-2025 Intel Corporation. * * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef VM_CONFIG_H_ -#define VM_CONFIG_H_ +#ifndef X86_VM_CONFIG_H_ +#define X86_VM_CONFIG_H_ -#include -#include -#include -#include -#include -#include #include -#include -#include -#include - -#define AFFINITY_CPU(n) (1UL << (n)) -#define MAX_VCPUS_PER_VM MAX_PCPU_NUM -#define MAX_VM_OS_NAME_LEN 32U -#define MAX_MOD_TAG_LEN 32U - -#if defined(CONFIG_SCHED_NOOP) -#define SERVICE_VM_IDLE "" -#elif defined(CONFIG_SCHED_PRIO) -#define SERVICE_VM_IDLE "" -#else -#define SERVICE_VM_IDLE "idle=halt " -#endif - -#define PCI_DEV_TYPE_NONE 0U -#define PCI_DEV_TYPE_PTDEV (1U << 0U) -#define PCI_DEV_TYPE_HVEMUL (1U << 1U) -#define PCI_DEV_TYPE_SERVICE_VM_EMUL (1U << 2U) -#define PCI_DEV_TYPE_DUMMY_MF_EMUL (1U << 3U) - -#define MAX_MMIO_DEV_NUM 2U - -#define CONFIG_SERVICE_VM .load_order = SERVICE_VM, \ - .severity = SEVERITY_SERVICE_VM - -#define CONFIG_SAFETY_VM .load_order = PRE_LAUNCHED_VM, \ - .severity = SEVERITY_SAFETY_VM - -#define CONFIG_PRE_STD_VM .load_order = PRE_LAUNCHED_VM, \ - .severity = SEVERITY_STANDARD_VM - -#define CONFIG_PRE_RT_VM .load_order = PRE_LAUNCHED_VM, \ - .severity = SEVERITY_RTVM - -#define CONFIG_POST_STD_VM .load_order = POST_LAUNCHED_VM, \ - .severity = SEVERITY_STANDARD_VM - -#define CONFIG_POST_RT_VM .load_order = POST_LAUNCHED_VM, \ - .severity = SEVERITY_RTVM /* Bitmask of guest flags that can be programmed by device model. Other bits are set by hypervisor only. */ #if (SERVICE_VM_NUM == 0) @@ -68,93 +21,7 @@ | GUEST_FLAG_RT | GUEST_FLAG_IO_COMPLETION_POLLING | GUEST_FLAG_PMU_PASSTHROUGH) #endif -/* ACRN guest severity */ -enum acrn_vm_severity { - SEVERITY_SAFETY_VM = 0x40U, - SEVERITY_RTVM = RTVM_SEVERITY_LEVEL, - SEVERITY_SERVICE_VM = 0x20U, - SEVERITY_STANDARD_VM = 0x10U, -}; - -struct vm_hpa_regions { - uint64_t start_hpa; - uint64_t size_hpa; -}; - -struct acrn_vm_mem_config { - uint64_t size; /* VM memory size configuration */ - uint64_t region_num; - struct vm_hpa_regions *host_regions; -}; - -enum os_kernel_type { - KERNEL_BZIMAGE = 1, - KERNEL_RAWIMAGE, - KERNEL_ELF, - KERNEL_UNKNOWN, -}; - -struct acrn_vm_os_config { - char name[MAX_VM_OS_NAME_LEN]; /* OS name, useful for debug */ - enum os_kernel_type kernel_type; /* used for kernel specifc loading method */ - char kernel_mod_tag[MAX_MOD_TAG_LEN]; /* multiboot module tag for kernel */ - char ramdisk_mod_tag[MAX_MOD_TAG_LEN]; /* multiboot module tag for ramdisk */ - char bootargs[MAX_BOOTARGS_SIZE]; /* boot args/cmdline */ - uint64_t kernel_load_addr; - uint64_t kernel_entry_addr; - uint64_t kernel_ramdisk_addr; -} __aligned(8); - -struct acrn_vm_acpi_config { - char acpi_mod_tag[MAX_MOD_TAG_LEN]; /* multiboot module tag for ACPI */ -} __aligned(8); - -/* the vbdf is assgined by device model */ -#define UNASSIGNED_VBDF 0xFFFFU - -struct acrn_vm_pci_dev_config { - uint32_t emu_type; /* the type how the device is emulated. */ - union pci_bdf vbdf; /* virtual BDF of PCI device */ - union pci_bdf pbdf; /* physical BDF of PCI device */ - char shm_region_name[32]; /* TODO: combine pbdf and shm_region_name into a union member */ - /* TODO: All device specific attributions need move to other place */ - struct target_vuart t_vuart; - uint16_t vuart_idx; - uint16_t vrp_sec_bus; /* use virtual root port's secondary bus as unique identification */ - uint8_t vrp_max_payload; /* vrp's dev cap's max payload */ - uint64_t vbar_base[PCI_BAR_COUNT]; /* vbar base address of PCI device, which is power-on default value */ - struct pci_pdev *pdev; /* the physical PCI device if it's a PT device */ - const struct pci_vdev_ops *vdev_ops; /* operations for PCI CFG read/write */ -} __aligned(8); - -struct pt_intx_config { - uint32_t phys_gsi; /* physical IOAPIC gsi to be forwarded to the VM */ - uint32_t virt_gsi; /* virtual IOAPIC gsi triggered on the vIOAPIC */ -} __aligned(8); - -struct acrn_vm_config { - enum acrn_vm_load_order load_order; /* specify the load order of VM */ - char name[MAX_VM_NAME_LEN]; /* VM name identifier */ - uint8_t reserved[2]; - uint8_t severity; /* severity of the VM */ - uint64_t cpu_affinity; /* The set bits represent the pCPUs the vCPUs of - * the VM may run on. - */ - uint64_t guest_flags; /* VM flags that we want to configure for guest - * Now we have two flags: - * GUEST_FLAG_SECURE_WORLD_ENABLED - * GUEST_FLAG_LAPIC_PASSTHROUGH - * We could add more guest flags in future; - */ - struct sched_params sched_params; /* Scheduler params for vCPUs of this VM */ - uint16_t companion_vm_id; /* The companion VM id for this VM */ - struct acrn_vm_mem_config memory; /* memory configuration of VM */ - struct epc_section epc; /* EPC memory configuration of VM */ - uint16_t pci_dev_num; /* indicate how many PCI devices in VM */ - struct acrn_vm_pci_dev_config *pci_devs; /* point to PCI devices BDF list */ - struct acrn_vm_os_config os_config; /* OS information the VM */ - struct acrn_vm_acpi_config acpi_config; /* ACPI config for the VM */ - +struct arch_vm_config { /* * below are variable length members (per build). * Service VM can get the vm_configs[] array through hypercall, but Service VM may not @@ -179,22 +46,11 @@ struct acrn_vm_config { uint32_t max_l2_pcbm; uint32_t max_l3_pcbm; - struct vuart_config vuart[MAX_VUART_NUM_PER_VM];/* vuart configuration for VM */ - bool pt_tpm2; - struct acrn_mmiodev mmiodevs[MAX_MMIO_DEV_NUM]; bool pt_p2sb_bar; /* whether to passthru p2sb bridge to pre-launched VM or not */ - uint16_t pt_intx_num; /* number of pt_intx_config entries pointed by pt_intx */ - struct pt_intx_config *pt_intx; /* stores the base address of struct pt_intx_config array */ -} __aligned(8); + struct epc_section epc; /* EPC memory configuration of VM */ +}; -struct acrn_vm_config *get_vm_config(uint16_t vm_id); -uint8_t get_vm_severity(uint16_t vm_id); -bool vm_has_matched_name(uint16_t vmid, const char *name); - -extern struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM]; -extern struct acrn_vm_config *const service_vm_config; - -#endif /* VM_CONFIG_H_ */ +#endif /* X86_VM_CONFIG_H_ */ diff --git a/hypervisor/include/common/vm.h b/hypervisor/include/common/vm.h index b0b0352eb..cb1f9d82b 100644 --- a/hypervisor/include/common/vm.h +++ b/hypervisor/include/common/vm.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include diff --git a/hypervisor/include/common/vm_config.h b/hypervisor/include/common/vm_config.h new file mode 100644 index 000000000..868f096e7 --- /dev/null +++ b/hypervisor/include/common/vm_config.h @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2018-2025 Intel Corporation. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef VM_CONFIG_H_ +#define VM_CONFIG_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define AFFINITY_CPU(n) (1UL << (n)) +#define MAX_VCPUS_PER_VM MAX_PCPU_NUM +#define MAX_VM_OS_NAME_LEN 32U +#define MAX_MOD_TAG_LEN 32U + +#if defined(CONFIG_SCHED_NOOP) +#define SERVICE_VM_IDLE "" +#elif defined(CONFIG_SCHED_PRIO) +#define SERVICE_VM_IDLE "" +#else +#define SERVICE_VM_IDLE "idle=halt " +#endif + +#define PCI_DEV_TYPE_NONE 0U +#define PCI_DEV_TYPE_PTDEV (1U << 0U) +#define PCI_DEV_TYPE_HVEMUL (1U << 1U) +#define PCI_DEV_TYPE_SERVICE_VM_EMUL (1U << 2U) +#define PCI_DEV_TYPE_DUMMY_MF_EMUL (1U << 3U) + +#define MAX_MMIO_DEV_NUM 2U + +#define CONFIG_SERVICE_VM .load_order = SERVICE_VM, \ + .severity = SEVERITY_SERVICE_VM + +#define CONFIG_SAFETY_VM .load_order = PRE_LAUNCHED_VM, \ + .severity = SEVERITY_SAFETY_VM + +#define CONFIG_PRE_STD_VM .load_order = PRE_LAUNCHED_VM, \ + .severity = SEVERITY_STANDARD_VM + +#define CONFIG_PRE_RT_VM .load_order = PRE_LAUNCHED_VM, \ + .severity = SEVERITY_RTVM + +#define CONFIG_POST_STD_VM .load_order = POST_LAUNCHED_VM, \ + .severity = SEVERITY_STANDARD_VM + +#define CONFIG_POST_RT_VM .load_order = POST_LAUNCHED_VM, \ + .severity = SEVERITY_RTVM + +/* ACRN guest severity */ +enum acrn_vm_severity { + SEVERITY_SAFETY_VM = 0x40U, + SEVERITY_RTVM = RTVM_SEVERITY_LEVEL, + SEVERITY_SERVICE_VM = 0x20U, + SEVERITY_STANDARD_VM = 0x10U, +}; + +struct vm_hpa_regions { + uint64_t start_hpa; + uint64_t size_hpa; +}; + +struct acrn_vm_mem_config { + uint64_t size; /* VM memory size configuration */ + uint64_t region_num; + struct vm_hpa_regions *host_regions; +}; + +enum os_kernel_type { + KERNEL_BZIMAGE = 1, + KERNEL_RAWIMAGE, + KERNEL_ELF, + KERNEL_UNKNOWN, +}; + +struct acrn_vm_os_config { + char name[MAX_VM_OS_NAME_LEN]; /* OS name, useful for debug */ + enum os_kernel_type kernel_type; /* used for kernel specifc loading method */ + char kernel_mod_tag[MAX_MOD_TAG_LEN]; /* multiboot module tag for kernel */ + char ramdisk_mod_tag[MAX_MOD_TAG_LEN]; /* multiboot module tag for ramdisk */ + char bootargs[MAX_BOOTARGS_SIZE]; /* boot args/cmdline */ + uint64_t kernel_load_addr; + uint64_t kernel_entry_addr; + uint64_t kernel_ramdisk_addr; +} __aligned(8); + +struct acrn_vm_acpi_config { + char acpi_mod_tag[MAX_MOD_TAG_LEN]; /* multiboot module tag for ACPI */ +} __aligned(8); + +/* the vbdf is assgined by device model */ +#define UNASSIGNED_VBDF 0xFFFFU + +struct acrn_vm_pci_dev_config { + uint32_t emu_type; /* the type how the device is emulated. */ + union pci_bdf vbdf; /* virtual BDF of PCI device */ + union pci_bdf pbdf; /* physical BDF of PCI device */ + char shm_region_name[32]; /* TODO: combine pbdf and shm_region_name into a union member */ + /* TODO: All device specific attributions need move to other place */ + struct target_vuart t_vuart; + uint16_t vuart_idx; + uint16_t vrp_sec_bus; /* use virtual root port's secondary bus as unique identification */ + uint8_t vrp_max_payload; /* vrp's dev cap's max payload */ + uint64_t vbar_base[PCI_BAR_COUNT]; /* vbar base address of PCI device, which is power-on default value */ + struct pci_pdev *pdev; /* the physical PCI device if it's a PT device */ + const struct pci_vdev_ops *vdev_ops; /* operations for PCI CFG read/write */ +} __aligned(8); + +struct pt_intx_config { + uint32_t phys_gsi; /* physical IOAPIC gsi to be forwarded to the VM */ + uint32_t virt_gsi; /* virtual IOAPIC gsi triggered on the vIOAPIC */ +} __aligned(8); + +struct acrn_vm_config { + enum acrn_vm_load_order load_order; /* specify the load order of VM */ + char name[MAX_VM_NAME_LEN]; /* VM name identifier */ + uint8_t reserved[2]; + uint8_t severity; /* severity of the VM */ + uint64_t cpu_affinity; /* The set bits represent the pCPUs the vCPUs of + * the VM may run on. + */ + uint64_t guest_flags; /* VM flags that we want to configure for guest + * Now we have two flags: + * GUEST_FLAG_SECURE_WORLD_ENABLED + * GUEST_FLAG_LAPIC_PASSTHROUGH + * We could add more guest flags in future; + */ + struct sched_params sched_params; /* Scheduler params for vCPUs of this VM */ + uint16_t companion_vm_id; /* The companion VM id for this VM */ + struct acrn_vm_mem_config memory; /* memory configuration of VM */ + uint16_t pci_dev_num; /* indicate how many PCI devices in VM */ + struct acrn_vm_pci_dev_config *pci_devs; /* point to PCI devices BDF list */ + struct acrn_vm_os_config os_config; /* OS information the VM */ + struct acrn_vm_acpi_config acpi_config; /* ACPI config for the VM */ + + struct vuart_config vuart[MAX_VUART_NUM_PER_VM];/* vuart configuration for VM */ + + struct acrn_mmiodev mmiodevs[MAX_MMIO_DEV_NUM]; + + uint16_t pt_intx_num; /* number of pt_intx_config entries pointed by pt_intx */ + struct pt_intx_config *pt_intx; /* stores the base address of struct pt_intx_config array */ + + struct arch_vm_config arch; +} __aligned(8); + +struct acrn_vm_config *get_vm_config(uint16_t vm_id); +uint8_t get_vm_severity(uint16_t vm_id); +bool vm_has_matched_name(uint16_t vmid, const char *name); + +extern struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM]; +extern struct acrn_vm_config *const service_vm_config; + +#endif /* VM_CONFIG_H_ */ diff --git a/hypervisor/include/debug/profiling_internal.h b/hypervisor/include/debug/profiling_internal.h index dab954333..6f987e05b 100644 --- a/hypervisor/include/debug/profiling_internal.h +++ b/hypervisor/include/debug/profiling_internal.h @@ -10,7 +10,7 @@ #ifdef PROFILING_ON #include -#include +#include #define MAX_MSR_LIST_NUM 15U #define MAX_PROFILING_MSR_STORE_NUM 1 diff --git a/hypervisor/include/dm/vuart.h b/hypervisor/include/dm/vuart.h index 6309c6c27..3832758f6 100644 --- a/hypervisor/include/dm/vuart.h +++ b/hypervisor/include/dm/vuart.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include /** * @addtogroup vp-dm_vperipheral diff --git a/hypervisor/quirks/security_vm_fixup.c b/hypervisor/quirks/security_vm_fixup.c index 03b2f74d0..2d556eb17 100644 --- a/hypervisor/quirks/security_vm_fixup.c +++ b/hypervisor/quirks/security_vm_fixup.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ static void tpm2_fixup(uint16_t vm_id) vtpm2 = get_acpi_mod_entry(ACPI_SIG_TPM2, mod->start); tpm2 = get_acpi_tbl(ACPI_SIG_TPM2); - if (config->pt_tpm2 && (vtpm2 != NULL) && (tpm2 != NULL)) { + if (config->arch.pt_tpm2 && (vtpm2 != NULL) && (tpm2 != NULL)) { for (i = 0U; i < MAX_MMIO_DEV_NUM; i++) { if (strncmp(config->mmiodevs[i].name, "tpm2", 4) == 0) { dev = &config->mmiodevs[i]; diff --git a/misc/config_tools/data/generic_board/generic_code/hybrid/pci_dev.c b/misc/config_tools/data/generic_board/generic_code/hybrid/pci_dev.c index 12c36cf12..cf1eee226 100644 --- a/misc/config_tools/data/generic_board/generic_code/hybrid/pci_dev.c +++ b/misc/config_tools/data/generic_board/generic_code/hybrid/pci_dev.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include #include #include #include diff --git a/misc/config_tools/data/generic_board/generic_code/hybrid/pt_intx.c b/misc/config_tools/data/generic_board/generic_code/hybrid/pt_intx.c index e11f52060..dd49ad582 100644 --- a/misc/config_tools/data/generic_board/generic_code/hybrid/pt_intx.c +++ b/misc/config_tools/data/generic_board/generic_code/hybrid/pt_intx.c @@ -4,5 +4,5 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include struct pt_intx_config vm0_pt_intx[1U] = {}; diff --git a/misc/config_tools/data/generic_board/generic_code/hybrid/vm_configurations.c b/misc/config_tools/data/generic_board/generic_code/hybrid/vm_configurations.c index 61edd6a02..f34a8c7de 100644 --- a/misc/config_tools/data/generic_board/generic_code/hybrid/vm_configurations.c +++ b/misc/config_tools/data/generic_board/generic_code/hybrid/vm_configurations.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include #include #include #include diff --git a/misc/config_tools/data/generic_board/generic_code/partitioned/pci_dev.c b/misc/config_tools/data/generic_board/generic_code/partitioned/pci_dev.c index ae7cf20e3..a3fbc90d6 100644 --- a/misc/config_tools/data/generic_board/generic_code/partitioned/pci_dev.c +++ b/misc/config_tools/data/generic_board/generic_code/partitioned/pci_dev.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include #include #include #include diff --git a/misc/config_tools/data/generic_board/generic_code/partitioned/pt_intx.c b/misc/config_tools/data/generic_board/generic_code/partitioned/pt_intx.c index 23570ce05..e37993340 100644 --- a/misc/config_tools/data/generic_board/generic_code/partitioned/pt_intx.c +++ b/misc/config_tools/data/generic_board/generic_code/partitioned/pt_intx.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include struct pt_intx_config vm0_pt_intx[1U] = {}; struct pt_intx_config vm1_pt_intx[1U] = {}; diff --git a/misc/config_tools/data/generic_board/generic_code/partitioned/vm_configurations.c b/misc/config_tools/data/generic_board/generic_code/partitioned/vm_configurations.c index e39639eb1..88dc843a8 100644 --- a/misc/config_tools/data/generic_board/generic_code/partitioned/vm_configurations.c +++ b/misc/config_tools/data/generic_board/generic_code/partitioned/vm_configurations.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include #include #include #include diff --git a/misc/config_tools/data/generic_board/generic_code/shared/pci_dev.c b/misc/config_tools/data/generic_board/generic_code/shared/pci_dev.c index 12c36cf12..cf1eee226 100644 --- a/misc/config_tools/data/generic_board/generic_code/shared/pci_dev.c +++ b/misc/config_tools/data/generic_board/generic_code/shared/pci_dev.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include #include #include #include diff --git a/misc/config_tools/data/generic_board/generic_code/shared/pt_intx.c b/misc/config_tools/data/generic_board/generic_code/shared/pt_intx.c index 9a766c61d..18d8b361b 100644 --- a/misc/config_tools/data/generic_board/generic_code/shared/pt_intx.c +++ b/misc/config_tools/data/generic_board/generic_code/shared/pt_intx.c @@ -4,4 +4,4 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include diff --git a/misc/config_tools/data/generic_board/generic_code/shared/vm_configurations.c b/misc/config_tools/data/generic_board/generic_code/shared/vm_configurations.c index e2c3cfb30..80c09673f 100644 --- a/misc/config_tools/data/generic_board/generic_code/shared/vm_configurations.c +++ b/misc/config_tools/data/generic_board/generic_code/shared/vm_configurations.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include +#include #include #include #include diff --git a/misc/config_tools/xforms/pci_dev.c.xsl b/misc/config_tools/xforms/pci_dev.c.xsl index f15cd667b..f98ade5de 100644 --- a/misc/config_tools/xforms/pci_dev.c.xsl +++ b/misc/config_tools/xforms/pci_dev.c.xsl @@ -18,7 +18,7 @@ - + diff --git a/misc/config_tools/xforms/pt_intx.c.xsl b/misc/config_tools/xforms/pt_intx.c.xsl index 4063fe458..694971816 100644 --- a/misc/config_tools/xforms/pt_intx.c.xsl +++ b/misc/config_tools/xforms/pt_intx.c.xsl @@ -18,7 +18,7 @@ - + diff --git a/misc/config_tools/xforms/vm_configurations.c.xsl b/misc/config_tools/xforms/vm_configurations.c.xsl index 8e4a5beef..5d00671cb 100644 --- a/misc/config_tools/xforms/vm_configurations.c.xsl +++ b/misc/config_tools/xforms/vm_configurations.c.xsl @@ -14,7 +14,7 @@ - + @@ -194,25 +194,25 @@ - + - + - + - + - + @@ -365,7 +365,7 @@ - + diff --git a/misc/hv_prebuild/Makefile b/misc/hv_prebuild/Makefile index 73fbf6f86..3d80c8799 100644 --- a/misc/hv_prebuild/Makefile +++ b/misc/hv_prebuild/Makefile @@ -25,7 +25,8 @@ BOARD_CFG_DIR := $(SCENARIO_CFG_DIR) PRE_BUILD_SRCS += main.c PRE_BUILD_SRCS += static_checks.c PRE_BUILD_SRCS += vm_cfg_checks.c -PRE_BUILD_SRCS += $(HV_SRC_DIR)/arch/x86/configs/vm_config.c +#PRE_BUILD_SRCS += $(HV_SRC_DIR)/arch/x86/configs/vm_config.c +PRE_BUILD_SRCS += $(HV_SRC_DIR)/common/vm_config.c PRE_BUILD_SRCS += $(SCENARIO_CFG_DIR)/vm_configurations.c PRE_BUILD_SRCS += $(BOARD_CFG_DIR)/pt_intx.c ifneq (,$(wildcard $(BOARD_CFG_DIR)/pci_dev.c)) diff --git a/misc/hv_prebuild/vm_cfg_checks.c b/misc/hv_prebuild/vm_cfg_checks.c index 20849d6c4..989ca117d 100644 --- a/misc/hv_prebuild/vm_cfg_checks.c +++ b/misc/hv_prebuild/vm_cfg_checks.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -31,11 +31,11 @@ static bool check_vm_clos_config(uint16_t vm_id) bool ret = true; struct acrn_vm_config *vm_config = get_vm_config(vm_id); - for (i = 0U; i < vm_config->num_pclosids; i++) { - if (((platform_clos_num != 0U) && (vm_config->pclosids[i] == platform_clos_num)) - || (vm_config->pclosids[i] > platform_clos_num)) { + for (i = 0U; i < vm_config->arch.num_pclosids; i++) { + if (((platform_clos_num != 0U) && (vm_config->arch.pclosids[i] == platform_clos_num)) + || (vm_config->arch.pclosids[i] > platform_clos_num)) { printf("vm%u: vcpu%u clos(%u) exceed the max clos(%u).", - vm_id, i, vm_config->pclosids[i], platform_clos_num); + vm_id, i, vm_config->arch.pclosids[i], platform_clos_num); ret = false; break; } @@ -71,7 +71,7 @@ bool sanitize_vm_config(void) if (((vm_config->guest_flags & GUEST_FLAG_RT) != 0U) && ((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH)== 0U)) { ret = false; - } else if (vm_config->epc.size != 0UL) { + } else if (vm_config->arch.epc.size != 0UL) { ret = false; } break; @@ -94,7 +94,7 @@ bool sanitize_vm_config(void) #endif if (ret && - (((vm_config->epc.size | vm_config->epc.base) & ~PAGE_MASK) != 0UL)) { + (((vm_config->arch.epc.size | vm_config->arch.epc.base) & ~PAGE_MASK) != 0UL)) { ret = false; }