Skip to content

Commit 3b2784e

Browse files
taoyuhongEddie Dong
authored andcommitted
HV: CAT: support config CAT from acrn_vm_config
When CAT is supported, UOS can setup acrn_vm_config.clos, to use CAT feature. Eg., struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = { { .guest_flags |= CLOS_REQUIRED, .clos = 1, }, }; sanitize_vm_config() will check if CAT is supported and vm_configs.clos is valid. Tracked-On: #2462 Signed-off-by: Tao Yuhong <yuhong.tao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 43ee559 commit 3b2784e

File tree

7 files changed

+48
-0
lines changed

7 files changed

+48
-0
lines changed

hypervisor/arch/x86/cat.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,19 @@ int32_t init_cat_cap_info(void)
5454

5555
return ret;
5656
}
57+
58+
59+
void setup_clos(uint16_t pcpu_id)
60+
{
61+
uint16_t i;
62+
uint32_t msr_index;
63+
uint64_t val;
64+
65+
if (cat_cap_info.enabled) {
66+
for (i = 0U; i < platform_clos_num; i++) {
67+
msr_index = platform_clos_array[i].msr_index;
68+
val = (uint64_t)platform_clos_array[i].clos_mask;
69+
msr_write_pcpu(msr_index, val, pcpu_id);
70+
}
71+
}
72+
}

hypervisor/arch/x86/cpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ void init_cpu_post(uint16_t pcpu_id)
230230
/* Wait for boot processor to signal all secondary cores to continue */
231231
wait_sync_change(&pcpu_sync, 0UL);
232232
}
233+
234+
setup_clos(pcpu_id);
233235
}
234236

235237
static uint16_t get_cpu_id_from_lapic_id(uint32_t lapic_id)

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <vmcs.h>
1919
#include <mmu.h>
2020
#include <sprintf.h>
21+
#include <cat.h>
2122

2223
inline uint64_t vcpu_get_gpreg(const struct acrn_vcpu *vcpu, uint32_t reg)
2324
{
@@ -678,6 +679,8 @@ int32_t prepare_vcpu(struct acrn_vm *vm, uint16_t pcpu_id)
678679
int32_t ret = 0;
679680
struct acrn_vcpu *vcpu = NULL;
680681
char thread_name[16];
682+
uint64_t orig_val, final_val;
683+
struct acrn_vm_config *conf;
681684

682685
ret = create_vcpu(pcpu_id, vm, &vcpu);
683686
if (ret != 0) {
@@ -686,6 +689,14 @@ int32_t prepare_vcpu(struct acrn_vm *vm, uint16_t pcpu_id)
686689

687690
set_pcpu_used(pcpu_id);
688691

692+
/* Update CLOS for this CPU */
693+
if (cat_cap_info.enabled) {
694+
conf = get_vm_config(vm->vm_id);
695+
orig_val = msr_read(MSR_IA32_PQR_ASSOC);
696+
final_val = (orig_val & 0xffffffffUL) | (((uint64_t)conf->clos) << 32UL);
697+
msr_write_pcpu(MSR_IA32_PQR_ASSOC, final_val, pcpu_id);
698+
}
699+
689700
INIT_LIST_HEAD(&vcpu->sched_obj.run_list);
690701
snprintf(thread_name, 16U, "vm%hu:vcpu%hu", vm->vm_id, vcpu->vcpu_id);
691702
(void)strncpy_s(vcpu->sched_obj.name, 16U, thread_name, 16U);

hypervisor/arch/x86/guest/vm.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <pgtable.h>
2323
#include <mmu.h>
2424
#include <logmsg.h>
25+
#include <cat.h>
2526

2627
vm_sw_loader_t vm_sw_loader;
2728

@@ -622,6 +623,21 @@ int32_t sanitize_vm_config(void)
622623
/* Nothing to do for a UNDEFINED_VM, break directly. */
623624
break;
624625
}
626+
627+
if ((vm_config->guest_flags & CLOS_REQUIRED) != 0U) {
628+
if (cat_cap_info.support) {
629+
if (vm_config->clos > cat_cap_info.clos_max) {
630+
pr_err("%s CLOS exceed MAX CLOS\n", __func__);
631+
ret = -EINVAL;
632+
} else {
633+
cat_cap_info.enabled = true;
634+
}
635+
} else {
636+
pr_err("%s set CLOS but CAT is not supported\n", __func__);
637+
ret = -EINVAL;
638+
}
639+
}
640+
625641
if (ret != 0) {
626642
break;
627643
}

hypervisor/include/arch/x86/cat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct cat_hw_info {
1919
};
2020

2121
extern struct cat_hw_info cat_cap_info;
22+
void setup_clos(uint16_t pcpu_id);
2223

2324
#define CAT_RESID_L3 1U
2425
#define CAT_RESID_L2 2U

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ struct acrn_vm_config {
209209
bool vm_vuart;
210210
#endif
211211

212+
uint16_t clos; /* if guest_flags has CAT_ENABLED, then VM use this CLOS */
212213
} __aligned(8);
213214

214215
/*

hypervisor/include/public/acrn_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#define SECURE_WORLD_ENABLED (1UL << 0U) /* Whether secure world is enabled */
5151
#define LAPIC_PASSTHROUGH (1UL << 1U) /* Whether LAPIC is passed through */
5252
#define IO_COMPLETION_POLLING (1UL << 2U) /* Whether need hypervisor poll IO completion */
53+
#define CLOS_REQUIRED (1UL << 3U) /* Whether CLOS is required */
5354

5455
/**
5556
* @brief Hypercall

0 commit comments

Comments
 (0)