Skip to content

Commit 43ee559

Browse files
taoyuhongEddie Dong
authored andcommitted
HV: CAT: capability enumaration
Enumarate capability of Cache Allocation Technology(CAT) on X86 platform, when HV init the primary cpu. If CAT is supported, store its info to global struct cat_hw_info. Tracked-On: #2462 Signed-off-by: Tao Yuhong <yuhong.tao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent cf524e6 commit 43ee559

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

hypervisor/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ C_SRCS += arch/x86/guest/vmcs.c
186186
C_SRCS += arch/x86/guest/vmexit.c
187187
S_SRCS += arch/x86/guest/vmx_asm.S
188188
C_SRCS += arch/x86/guest/trusty.c
189+
C_SRCS += arch/x86/cat.c
189190
C_SRCS += lib/misc.c
190191
C_SRCS += lib/string.c
191192
C_SRCS += lib/memory.c

hypervisor/arch/x86/cat.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include <types.h>
8+
#include <cpu.h>
9+
#include <cpu_caps.h>
10+
#include <cpufeatures.h>
11+
#include <cpuid.h>
12+
#include <msr.h>
13+
#include <errno.h>
14+
#include <logmsg.h>
15+
#include <cat.h>
16+
#include <board.h>
17+
18+
struct cat_hw_info cat_cap_info;
19+
20+
int32_t init_cat_cap_info(void)
21+
{
22+
uint32_t eax = 0U, ebx = 0U, ecx = 0U, edx = 0U;
23+
int32_t ret = 0;
24+
25+
if (cpu_has_cap(X86_FEATURE_CAT)) {
26+
cpuid_subleaf(CPUID_RSD_ALLOCATION, 0, &eax, &ebx, &ecx, &edx);
27+
/* If support L3 CAT, EBX[1] is set */
28+
if ((ebx & 2U) != 0U) {
29+
cat_cap_info.res_id = CAT_RESID_L3;
30+
}
31+
32+
/* If support L2 CAT, EBX[2] is set */
33+
if ((ebx & 4U) != 0U) {
34+
cat_cap_info.res_id = CAT_RESID_L2;
35+
}
36+
37+
cat_cap_info.support = true;
38+
39+
/* CPUID.(EAX=0x10,ECX=ResID):EAX[4:0] reports the length of CBM supported
40+
* CPUID.(EAX=0x10,ECX=ResID):EBX[31:0] indicates the corresponding uints
41+
* may be used by other entities such as graphic and H/W outside processor.
42+
* CPUID.(EAX=0x10,ECX=ResID):EDX[15:0] reports the maximun CLOS supported
43+
*/
44+
cpuid_subleaf(CPUID_RSD_ALLOCATION, cat_cap_info.res_id, &eax, &ebx, &ecx, &edx);
45+
cat_cap_info.cbm_len = (uint16_t)((eax & 0xfU) + 1U);
46+
cat_cap_info.bitmask = ebx;
47+
cat_cap_info.clos_max = (uint16_t)(edx & 0xffffU);
48+
49+
if ((platform_clos_num != 0U) && ((cat_cap_info.clos_max + 1U) != platform_clos_num)) {
50+
pr_err("%s clos_max:%hu, platform_clos_num:%u\n", __func__, cat_cap_info.clos_max, platform_clos_num);
51+
ret = -EINVAL;
52+
}
53+
}
54+
55+
return ret;
56+
}

hypervisor/arch/x86/cpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <vm.h>
2424
#include <ld_sym.h>
2525
#include <logmsg.h>
26+
#include <cat.h>
2627

2728
struct per_cpu_region per_cpu_data[CONFIG_MAX_PCPU_NUM] __aligned(PAGE_SIZE);
2829
static uint16_t phys_cpu_num = 0U;
@@ -130,6 +131,12 @@ void init_cpu_pre(uint16_t pcpu_id_args)
130131
if (ret != 0) {
131132
panic("System IOAPIC info is incorrect!");
132133
}
134+
135+
ret = init_cat_cap_info();
136+
if (ret != 0) {
137+
panic("Platform CAT info is incorrect!");
138+
}
139+
133140
} else {
134141
/* Switch this CPU to use the same page tables set-up by the
135142
* primary/boot CPU

hypervisor/include/arch/x86/cat.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef CAT_H
8+
#define CAT_H
9+
10+
/* The intel Resource Director Tech(RDT) based Cache Allocation Tech support */
11+
struct cat_hw_info {
12+
bool support; /* If L2/L3 CAT supported */
13+
bool enabled; /* If any VM setup CLOS */
14+
uint32_t bitmask; /* Used by other entities */
15+
uint16_t cbm_len; /* Length of Cache mask in bits */
16+
uint16_t clos_max; /* Maximum CLOS supported, the number of cache masks */
17+
18+
uint32_t res_id;
19+
};
20+
21+
extern struct cat_hw_info cat_cap_info;
22+
23+
#define CAT_RESID_L3 1U
24+
#define CAT_RESID_L2 2U
25+
26+
int32_t init_cat_cap_info(void);
27+
28+
#endif /* CAT_H */

hypervisor/include/arch/x86/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#define X86_FEATURE_SMEP ((FEAT_7_0_EBX << 5U) + 7U)
7474
#define X86_FEATURE_ERMS ((FEAT_7_0_EBX << 5U) + 9U)
7575
#define X86_FEATURE_INVPCID ((FEAT_7_0_EBX << 5U) + 10U)
76+
#define X86_FEATURE_CAT ((FEAT_7_0_EBX << 5U) + 15U)
7677
#define X86_FEATURE_SMAP ((FEAT_7_0_EBX << 5U) + 20U)
7778

7879
/* Intel-defined CPU features, CPUID level 0x00000007 (EDX)*/

hypervisor/include/arch/x86/cpuid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#define CPUID_TLB 2U
101101
#define CPUID_SERIALNUM 3U
102102
#define CPUID_EXTEND_FEATURE 7U
103+
#define CPUID_RSD_ALLOCATION 0x10U
103104
#define CPUID_MAX_EXTENDED_FUNCTION 0x80000000U
104105
#define CPUID_EXTEND_FUNCTION_1 0x80000001U
105106
#define CPUID_EXTEND_FUNCTION_2 0x80000002U

0 commit comments

Comments
 (0)