Skip to content

Commit 92bbb54

Browse files
ZideChen0wenlingz
authored andcommitted
hv: rearrange data structure for emulated MSRs
Create two arrays for emulated MSRs: - guest_msrs[] in struct acrn_vcpu_arch: emulation for all MSRs that are included in emulated_guest_msrs[]. - world_msrs[] in struct cpu_context: it has separate copies for secure and normal world for those MSRs that are in the first NUM_WORLD_MSRS entries in emulated_guest_msrs[]. Split vmsr.c/emulated_msrs[] into 3 smaller arrays: - emulated_guest_msrs[]: corresponding MSRs are emulated in guest_msrs[] - mtrr_msrs[]: emulated MTRRs are saved in vMTRR module - unsupported_msrs[]: GP for any guest accesses Tracked-On: #1867 Signed-off-by: Zide Chen <zide.chen@intel.com>
1 parent 7fce246 commit 92bbb54

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

hypervisor/arch/x86/guest/vmsr.c

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,30 @@ enum rw_mode {
1414
READ_WRITE
1515
};
1616

17-
/*
18-
* List of intercepted MSRs.
19-
* If any MSRs appear in this array but not handled in any swith statements
20-
* in either rdmsr_vmexit_handler() or wrmsr_vmexit_handler(), a GP will
21-
* be thrown to the guest for any R/W accesses.
22-
*/
23-
#define NUM_EMULATED_MSR 96U
24-
static const uint32_t emulated_msrs[NUM_EMULATED_MSR] = {
25-
/* Emulated MSRs */
17+
static const uint32_t emulated_guest_msrs[NUM_GUEST_MSRS] = {
18+
/*
19+
* MSRs that trusty may touch and need isolation between secure and normal world
20+
* This may include MSR_IA32_TSC_ADJUST, MSR_IA32_STAR, MSR_IA32_LSTAR, MSR_IA32_FMASK,
21+
* MSR_IA32_KERNEL_GS_BASE, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_EIP
22+
*
23+
* Number of entries: NUM_WORLD_MSRS
24+
*/
25+
MSR_IA32_PAT,
26+
27+
/*
28+
* MSRs don't need isolation between worlds
29+
* Number of entries: NUM_COMMON_MSRS
30+
*/
2631
MSR_IA32_TSC_DEADLINE,
2732
MSR_IA32_BIOS_UPDT_TRIG,
2833
MSR_IA32_BIOS_SIGN_ID,
2934
MSR_IA32_TIME_STAMP_COUNTER,
30-
MSR_IA32_PAT,
3135
MSR_IA32_APIC_BASE,
36+
MSR_IA32_PERF_CTL
37+
};
3238

33-
MSR_IA32_PERF_CTL,
34-
39+
#define NUM_MTRR_MSRS 13U
40+
static const uint32_t mtrr_msrs[NUM_MTRR_MSRS] = {
3541
MSR_IA32_MTRR_CAP,
3642
MSR_IA32_MTRR_DEF_TYPE,
3743
MSR_IA32_MTRR_FIX64K_00000,
@@ -44,10 +50,12 @@ static const uint32_t emulated_msrs[NUM_EMULATED_MSR] = {
4450
MSR_IA32_MTRR_FIX4K_E0000,
4551
MSR_IA32_MTRR_FIX4K_E8000,
4652
MSR_IA32_MTRR_FIX4K_F0000,
47-
MSR_IA32_MTRR_FIX4K_F8000,
48-
49-
/* Following MSRs intercepted, and throw GP for any access */
53+
MSR_IA32_MTRR_FIX4K_F8000
54+
};
5055

56+
/* Following MSRs are intercepted, but it throws GPs for any guest accesses */
57+
#define NUM_UNSUPPORTED_MSRS 76U
58+
static const uint32_t unsupported_msrs[NUM_UNSUPPORTED_MSRS] = {
5159
/* Variable MTRRs are not supported */
5260
MSR_IA32_MTRR_PHYSBASE_0,
5361
MSR_IA32_MTRR_PHYSMASK_0,
@@ -145,8 +153,8 @@ static const uint32_t emulated_msrs[NUM_EMULATED_MSR] = {
145153
/* MSR 0xC90 ... 0xD8F, not in this array */
146154
};
147155

148-
#define NUM_X2APIC_MSR 44U
149-
static const uint32_t x2apic_msrs[NUM_X2APIC_MSR] = {
156+
#define NUM_X2APIC_MSRS 44U
157+
static const uint32_t x2apic_msrs[NUM_X2APIC_MSRS] = {
150158
MSR_IA32_EXT_XAPICID,
151159
MSR_IA32_EXT_APIC_VERSION,
152160
MSR_IA32_EXT_APIC_TPR,
@@ -241,7 +249,7 @@ static void intercept_x2apic_msrs(uint8_t *msr_bitmap_arg, enum rw_mode mode)
241249
uint8_t *msr_bitmap = msr_bitmap_arg;
242250
uint32_t i;
243251

244-
for (i = 0U; i < NUM_X2APIC_MSR; i++) {
252+
for (i = 0U; i < NUM_X2APIC_MSRS; i++) {
245253
enable_msr_interception(msr_bitmap, x2apic_msrs[i], mode);
246254
}
247255
}
@@ -263,12 +271,20 @@ void init_msr_emulation(struct acrn_vcpu *vcpu)
263271
if (is_vcpu_bsp(vcpu)) {
264272
msr_bitmap = vcpu->vm->arch_vm.msr_bitmap;
265273

266-
for (i = 0U; i < NUM_EMULATED_MSR; i++) {
267-
enable_msr_interception(msr_bitmap, emulated_msrs[i], READ_WRITE);
274+
for (i = 0U; i < NUM_GUEST_MSRS; i++) {
275+
enable_msr_interception(msr_bitmap, emulated_guest_msrs[i], READ_WRITE);
276+
}
277+
278+
for (i = 0U; i < NUM_MTRR_MSRS; i++) {
279+
enable_msr_interception(msr_bitmap, mtrr_msrs[i], READ_WRITE);
268280
}
269281

270282
intercept_x2apic_msrs(msr_bitmap, READ_WRITE);
271283

284+
for (i = 0U; i < NUM_UNSUPPORTED_MSRS; i++) {
285+
enable_msr_interception(msr_bitmap, unsupported_msrs[i], READ_WRITE);
286+
}
287+
272288
/* RDT-A disabled: CPUID.07H.EBX[12], CPUID.10H */
273289
for (msr = MSR_IA32_L3_MASK_0; msr < MSR_IA32_BNDCFGS; msr++) {
274290
enable_msr_interception(msr_bitmap, msr, READ_WRITE);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ struct ext_context {
166166
#define NORMAL_WORLD 0
167167
#define SECURE_WORLD 1
168168

169+
#define NUM_WORLD_MSRS 1U
170+
#define NUM_COMMON_MSRS 6U
171+
#define NUM_GUEST_MSRS (NUM_WORLD_MSRS + NUM_COMMON_MSRS)
172+
169173
struct event_injection_info {
170174
uint32_t intr_info;
171175
uint32_t error_code;
@@ -174,6 +178,9 @@ struct event_injection_info {
174178
struct cpu_context {
175179
struct run_context run_ctx;
176180
struct ext_context ext_ctx;
181+
182+
/* per world MSRs, need isolation between secure and normal world */
183+
uint32_t world_msrs[NUM_WORLD_MSRS];
177184
};
178185

179186
/* Intel SDM 24.8.2, the address must be 16-byte aligned */
@@ -201,6 +208,9 @@ struct acrn_vcpu_arch {
201208
int cur_context;
202209
struct cpu_context contexts[NR_WORLD];
203210

211+
/* common MSRs, world_msrs[] is a subset of it */
212+
uint64_t guest_msrs[NUM_GUEST_MSRS];
213+
204214
uint16_t vpid;
205215

206216
/* Holds the information needed for IRQ/exception handling. */

0 commit comments

Comments
 (0)