hv: Build mptable for guest if VM type is Pre-Launched

ACRN builds mptable for pre-launched VMs. It uses CONFIG_PARTITION_MODE
to compile mptable source code and related support. This patch removes
the macro and checks if the type of VM is pre-launched to build mptable.

Tracked-On: #2941
Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Sainath Grandhi 2019-04-05 11:26:02 -07:00 committed by Eddie Dong
parent 869de39757
commit 16a2af5715
9 changed files with 24 additions and 40 deletions

View File

@ -228,9 +228,7 @@ C_SRCS += dm/vioapic.c
C_SRCS += dm/io_req.c
C_SRCS += dm/vpci/vdev.c
C_SRCS += dm/vpci/vpci.c
ifeq ($(CONFIG_PARTITION_MODE),y)
C_SRCS += dm/vmptable.c
endif
C_SRCS += dm/vpci/vhostbridge.c
C_SRCS += dm/vpci/pci_pt.c
C_SRCS += dm/vpci/vmsi.c

View File

@ -91,6 +91,8 @@ bool sanitize_vm_config(void)
} else if (((vm_config->guest_flags & GUEST_FLAG_LAPIC_PASSTHROUGH) != 0U)
&& ((vm_config->guest_flags & GUEST_FLAG_RT) == 0U)) {
ret = false;
} else if (vm_config->mptable == NULL) {
ret = false;
} else {
pre_launch_pcpu_bitmap |= vm_config->pcpu_bitmap;
}

View File

@ -145,26 +145,6 @@ static inline uint16_t get_vm_bsp_pcpu_id(const struct acrn_vm_config *vm_config
return (cpu_id < get_pcpu_nums()) ? cpu_id : INVALID_CPU_ID;
}
#ifdef CONFIG_PARTITION_MODE
/**
* @pre vm_config != NULL
*/
uint16_t get_vm_pcpu_nums(const struct acrn_vm_config *vm_config)
{
uint16_t i, host_pcpu_num, pcpu_num = 0U;
uint64_t cpu_bitmap = vm_config->pcpu_bitmap;
host_pcpu_num = get_pcpu_nums();
for (i = 0U; i < host_pcpu_num ; i++) {
if (bitmap_test(i, &cpu_bitmap)) {
pcpu_num++;
}
}
return pcpu_num;
}
#endif
/**
* @pre vm != NULL && vm_config != NULL
*/
@ -635,9 +615,9 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config)
err = create_vm(vm_id, vm_config, &vm);
if (err == 0) {
#ifdef CONFIG_PARTITION_MODE
(void)mptable_build(vm);
#endif
if (is_prelaunched_vm(vm)) {
(void)mptable_build(vm);
}
for (i = 0U; i < get_pcpu_nums(); i++) {
if (bitmap_test(i, &vm_config->pcpu_bitmap)) {

View File

@ -57,7 +57,7 @@ static struct mptable_info mptable_template = {
static struct proc_entry proc_entry_template = {
.type = MPCT_ENTRY_PROCESSOR,
.apic_version = LAPIC_VERSION,
.apic_version = LAPIC_VERSION_NUM,
.cpu_flags = PROCENTRY_FLAG_EN,
.cpu_signature = MPEP_SIG,
.feature_flags = MPEP_FEATURES
@ -78,7 +78,9 @@ static uint8_t mpt_compute_checksum(void *base, size_t len)
}
/**
* @pre vm_config != NULL
* @pre vm != NULL
* @pre vm->vm_id < CONFIG_MAX_VM_NUM
* @pre vm_configs[vm->vm_id].mptable != NULL
*/
int32_t mptable_build(struct acrn_vm *vm)
{
@ -90,11 +92,12 @@ int32_t mptable_build(struct acrn_vm *vm)
uint16_t i;
uint16_t vcpu_num;
uint64_t pcpu_bitmap = 0U;
struct mptable_info *mptable = &vm->mptable;
struct mptable_info *mptable;
struct acrn_vm_config *vm_config;
vm_config = get_vm_config(vm->vm_id);
vcpu_num = get_vm_pcpu_nums(vm_config);
mptable = vm_config->mptable;
vcpu_num = vm_config->cpu_num;
pcpu_bitmap = vm_config->pcpu_bitmap;
(void *)memcpy_s((void *)mptable, sizeof(struct mptable_info),
(const void *)&mptable_template, sizeof(struct mptable_info));

View File

@ -29,10 +29,6 @@
#include <e820.h>
#include <vm_config.h>
#ifdef CONFIG_PARTITION_MODE
#include <mptable.h>
#endif
#define INVALID_VM_ID 0xffffU
struct vm_hw_info {
@ -151,9 +147,6 @@ struct acrn_vm {
struct vcpuid_entry vcpuid_entries[MAX_VM_VCPUID_ENTRIES];
struct acrn_vpci vpci;
#ifdef CONFIG_PARTITION_MODE
struct mptable_info mptable;
#endif
uint8_t vrtc_offset;
spinlock_t softirq_dev_lock;
@ -222,9 +215,6 @@ int32_t general_sw_loader(struct acrn_vm *vm);
typedef int32_t (*vm_sw_loader_t)(struct acrn_vm *vm);
extern vm_sw_loader_t vm_sw_loader;
#ifdef CONFIG_PARTITION_MODE
uint16_t get_vm_pcpu_nums(const struct acrn_vm_config *vm_config);
#endif
void vrtc_init(struct acrn_vm *vm);
bool is_lapic_pt(const struct acrn_vm *vm);

View File

@ -11,6 +11,7 @@
#include <pci.h>
#include <multiboot.h>
#include <acrn_common.h>
#include <mptable.h>
#include <vm_configurations.h>
#define PLUG_CPU(n) (1U << (n))
@ -47,6 +48,7 @@ struct acrn_vm_config {
char name[MAX_VM_OS_NAME_LEN]; /* VM name identifier, useful for debug. */
const uint8_t uuid[16]; /* UUID of the VM */
uint64_t pcpu_bitmap; /* from pcpu bitmap, we could know VM core number */
uint16_t cpu_num; /* Number of vCPUs for the VM */
uint64_t guest_flags; /* VM flags that we want to configure for guest
* Now we have two flags:
* GUEST_FLAG_SECURE_WORLD_ENABLED
@ -60,6 +62,7 @@ struct acrn_vm_config {
uint16_t clos; /* if guest_flags has GUEST_FLAG_CLOS_REQUIRED, then VM use this CLOS */
bool vm_vuart;
struct mptable_info *mptable; /* Pointer to mptable struct if VM type is pre-launched */
} __aligned(8);
struct acrn_vm_config *get_vm_config(uint16_t vm_id);

View File

@ -33,7 +33,7 @@
*/
#define MPTABLE_MAX_LENGTH 65536U
#define LAPIC_VERSION 16U
#define LAPIC_VERSION_NUM 16U
#define MP_SPECREV 4U
#define MPFP_SIG "_MP_"

View File

@ -11,6 +11,8 @@
extern struct acrn_vm_pci_ptdev_config vm0_pci_ptdevs[VM0_CONFIG_PCI_PTDEV_NUM];
extern struct acrn_vm_pci_ptdev_config vm1_pci_ptdevs[VM1_CONFIG_PCI_PTDEV_NUM];
static struct mptable_info vm_mptables[CONFIG_MAX_VM_NUM];
struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
{ /* VM0 */
.type = PRE_LAUNCHED_VM,
@ -19,6 +21,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
0x81U, 0x09U, 0xf2U, 0x01U, 0xebU, 0xd6U, 0x1aU, 0x5eU},
/* 26c5e0d8-8f8a-47d8-8109-f201ebd61a5e */
.pcpu_bitmap = VM0_CONFIG_PCPU_BITMAP,
.cpu_num = VM0_CONFIG_NUM_CPUS,
.guest_flags = GUEST_FLAG_IO_COMPLETION_POLLING,
.clos = 0U,
.memory = {
@ -37,6 +40,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
.vm_vuart = true,
.pci_ptdev_num = VM0_CONFIG_PCI_PTDEV_NUM,
.pci_ptdevs = vm0_pci_ptdevs,
.mptable = &vm_mptables[0],
},
{ /* VM1 */
.type = PRE_LAUNCHED_VM,
@ -45,6 +49,7 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
0xbcU, 0x58U, 0x76U, 0x05U, 0x83U, 0x7fU, 0x93U, 0x5eU},
/* dd87ce08-66f9-473d-bc58-7605837f935e */
.pcpu_bitmap = VM1_CONFIG_PCPU_BITMAP,
.cpu_num = VM1_CONFIG_NUM_CPUS,
.guest_flags = GUEST_FLAG_IO_COMPLETION_POLLING,
.clos = 0U,
.memory = {
@ -63,5 +68,6 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
.vm_vuart = true,
.pci_ptdev_num = VM1_CONFIG_PCI_PTDEV_NUM,
.pci_ptdevs = vm1_pci_ptdevs,
.mptable = &vm_mptables[1],
},
};

View File

@ -20,6 +20,7 @@
*/
#define VM0_CONFIG_PCPU_BITMAP (PLUG_CPU(0) | PLUG_CPU(2))
#define VM0_CONFIG_NUM_CPUS 2U
#define VM0_CONFIG_MEM_START_HPA 0x100000000UL
#define VM0_CONFIG_MEM_SIZE 0x20000000UL
#define VM0_CONFIG_OS_BOOTARG_ROOT "root=/dev/sda3 "
@ -28,6 +29,7 @@
#define VM0_CONFIG_PCI_PTDEV_NUM 3U
#define VM1_CONFIG_PCPU_BITMAP (PLUG_CPU(1) | PLUG_CPU(3))
#define VM1_CONFIG_NUM_CPUS 2U
#define VM1_CONFIG_MEM_START_HPA 0x120000000UL
#define VM1_CONFIG_MEM_SIZE 0x20000000UL
#define VM1_CONFIG_OS_BOOTARG_ROOT "root=/dev/sda3 "