mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-07 03:04:49 +00:00
hv:check pcpu numbers during init_pcpu_pre
it will panic if phys_cpu_num > CONFIG_MAX_PCPU_NUM during init_pcpu_pre,after that no need to check it again. Tracked-On: #861 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
This commit is contained in:
parent
5a03a5df05
commit
489937f7b8
@ -46,20 +46,20 @@ static void print_hv_banner(void);
|
|||||||
static uint16_t get_pcpu_id_from_lapic_id(uint32_t lapic_id);
|
static uint16_t get_pcpu_id_from_lapic_id(uint32_t lapic_id);
|
||||||
static uint64_t start_tsc __attribute__((__section__(".bss_noinit")));
|
static uint64_t start_tsc __attribute__((__section__(".bss_noinit")));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @pre phys_cpu_num <= CONFIG_MAX_PCPU_NUM
|
||||||
|
*/
|
||||||
static bool init_percpu_lapic_id(void)
|
static bool init_percpu_lapic_id(void)
|
||||||
{
|
{
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint16_t pcpu_num;
|
|
||||||
uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM];
|
uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM];
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
/* Save all lapic_id detected via parse_mdt in lapic_id_array */
|
/* Save all lapic_id detected via parse_mdt in lapic_id_array */
|
||||||
pcpu_num = parse_madt(lapic_id_array);
|
phys_cpu_num = parse_madt(lapic_id_array);
|
||||||
|
|
||||||
if (pcpu_num != 0U) {
|
if ((phys_cpu_num != 0U) && (phys_cpu_num <= CONFIG_MAX_PCPU_NUM)) {
|
||||||
phys_cpu_num = pcpu_num;
|
for (i = 0U; i < phys_cpu_num; i++) {
|
||||||
|
|
||||||
for (i = 0U; (i < pcpu_num) && (i < CONFIG_MAX_PCPU_NUM); i++) {
|
|
||||||
per_cpu(lapic_id, i) = lapic_id_array[i];
|
per_cpu(lapic_id, i) = lapic_id_array[i];
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
@ -81,6 +81,9 @@ static void pcpu_set_current_state(uint16_t pcpu_id, enum pcpu_boot_state state)
|
|||||||
per_cpu(boot_state, pcpu_id) = state;
|
per_cpu(boot_state, pcpu_id) = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @post return <= CONFIG_MAX_PCPU_NUM
|
||||||
|
*/
|
||||||
uint16_t get_pcpu_nums(void)
|
uint16_t get_pcpu_nums(void)
|
||||||
{
|
{
|
||||||
return phys_cpu_num;
|
return phys_cpu_num;
|
||||||
@ -267,7 +270,7 @@ static uint16_t get_pcpu_id_from_lapic_id(uint32_t lapic_id)
|
|||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint16_t pcpu_id = INVALID_CPU_ID;
|
uint16_t pcpu_id = INVALID_CPU_ID;
|
||||||
|
|
||||||
for (i = 0U; (i < phys_cpu_num) && (i < CONFIG_MAX_PCPU_NUM); i++) {
|
for (i = 0U; i < phys_cpu_num; i++) {
|
||||||
if (per_cpu(lapic_id, i) == lapic_id) {
|
if (per_cpu(lapic_id, i) == lapic_id) {
|
||||||
pcpu_id = i;
|
pcpu_id = i;
|
||||||
break;
|
break;
|
||||||
|
@ -420,9 +420,6 @@ int32_t detect_hardware_support(void)
|
|||||||
} else if (is_vmx_disabled()) {
|
} else if (is_vmx_disabled()) {
|
||||||
printf("%s, VMX can not be enabled\n", __func__);
|
printf("%s, VMX can not be enabled\n", __func__);
|
||||||
ret = -ENODEV;
|
ret = -ENODEV;
|
||||||
} else if (get_pcpu_nums() > CONFIG_MAX_PCPU_NUM) {
|
|
||||||
printf("%s, pcpu number(%d) is out of range\n", __func__, get_pcpu_nums());
|
|
||||||
ret = -ENODEV;
|
|
||||||
} else if (!pcpu_has_cap(X86_FEATURE_X2APIC)) {
|
} else if (!pcpu_has_cap(X86_FEATURE_X2APIC)) {
|
||||||
printf("%s, x2APIC not supported\n", __func__);
|
printf("%s, x2APIC not supported\n", __func__);
|
||||||
ret = -ENODEV;
|
ret = -ENODEV;
|
||||||
|
@ -632,6 +632,9 @@ static inline void clac(void)
|
|||||||
asm volatile ("clac" : : : "memory");
|
asm volatile ("clac" : : : "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @post return <= CONFIG_MAX_PCPU_NUM
|
||||||
|
*/
|
||||||
uint16_t get_pcpu_nums(void);
|
uint16_t get_pcpu_nums(void);
|
||||||
bool is_pcpu_active(uint16_t pcpu_id);
|
bool is_pcpu_active(uint16_t pcpu_id);
|
||||||
uint64_t get_active_pcpu_bitmap(void);
|
uint64_t get_active_pcpu_bitmap(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user