Skip to content

Commit 744e09b

Browse files
binbinwu1lijinxia
authored andcommitted
hv: define 4 vcpu modes
move enum vm_cpu_mode to guest.h move enum vm_paging_mode to guest.h replace REAL_MODE with CPU_MODE_REAL replace PAGE_PROTECTED_MODE with CPU_MODE_64BIT Signed-off-by: Binbin Wu <binbin.wu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent cb26228 commit 744e09b

File tree

7 files changed

+38
-42
lines changed

7 files changed

+38
-42
lines changed

hypervisor/arch/x86/guest/instr_emul_wrapper.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,6 @@ struct seg_desc {
124124
#define SEG_DESC_GRANULARITY(access) (((access) & 0x8000) ? 1 : 0)
125125
#define SEG_DESC_UNUSABLE(access) (((access) & 0x10000) ? 1 : 0)
126126

127-
enum vm_cpu_mode {
128-
CPU_MODE_REAL,
129-
CPU_MODE_PROTECTED,
130-
CPU_MODE_COMPATIBILITY, /* IA-32E mode (CS.L = 0) */
131-
CPU_MODE_64BIT, /* IA-32E mode (CS.L = 1) */
132-
};
133-
134-
enum vm_paging_mode {
135-
PAGING_MODE_FLAT,
136-
PAGING_MODE_32,
137-
PAGING_MODE_PAE,
138-
PAGING_MODE_64,
139-
};
140-
141127
struct vm_guest_paging {
142128
uint64_t cr3;
143129
int cpl;

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ void reset_vcpu(struct vcpu *vcpu)
265265
void init_vcpu(struct vcpu *vcpu)
266266
{
267267
if (is_vcpu_bsp(vcpu))
268-
vcpu->arch_vcpu.cpu_mode = PAGE_PROTECTED_MODE;
268+
vcpu->arch_vcpu.cpu_mode = CPU_MODE_64BIT;
269269
else
270-
vcpu->arch_vcpu.cpu_mode = REAL_MODE;
270+
vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL;
271271
/* init_vmcs is delayed to vcpu vmcs launch first time */
272272
}
273273

@@ -336,9 +336,9 @@ int prepare_vcpu(struct vm *vm, int pcpu_id)
336336
if (!vm_sw_loader)
337337
vm_sw_loader = general_sw_loader;
338338
vm_sw_loader(vm, vcpu);
339-
vcpu->arch_vcpu.cpu_mode = PAGE_PROTECTED_MODE;
339+
vcpu->arch_vcpu.cpu_mode = CPU_MODE_64BIT;
340340
} else {
341-
vcpu->arch_vcpu.cpu_mode = REAL_MODE;
341+
vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL;
342342
}
343343

344344
/* init_vmcs is delayed to vcpu vmcs launch first time */

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic)
10651065
if (--target_vcpu->arch_vcpu.nr_sipi > 0)
10661066
return 0;
10671067

1068-
target_vcpu->arch_vcpu.cpu_mode = REAL_MODE;
1068+
target_vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL;
10691069
target_vcpu->arch_vcpu.sipi_vector = vec;
10701070
pr_err("Start Secondary VCPU%d for VM[%d]...",
10711071
target_vcpu->vcpu_id,

hypervisor/arch/x86/vmexit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static int write_cr0(struct vcpu *vcpu, uint64_t value)
236236
* transition from real mode to paged-protected mode
237237
*/
238238
if (!is_vcpu_bsp(vcpu) &&
239-
(vcpu->arch_vcpu.cpu_mode == REAL_MODE) &&
239+
(vcpu->arch_vcpu.cpu_mode == CPU_MODE_REAL) &&
240240
(value & CR0_PG) && (value & CR0_PE)) {
241241
/* Enable protected mode */
242242
value32 = exec_vmread(VMX_ENTRY_CONTROLS);

hypervisor/arch/x86/vmx.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ static void init_guest_state(struct vcpu *vcpu)
264264

265265
/* Setup guest control register values */
266266
/* Set up guest CRO field */
267-
if (get_vcpu_mode(vcpu) == REAL_MODE) {
267+
if (get_vcpu_mode(vcpu) == CPU_MODE_REAL) {
268268
/*cur_context->cr0 = (CR0_CD | CR0_NW | CR0_ET | CR0_NE);*/
269269
cur_context->cr0 = CR0_ET | CR0_NE;
270270
cur_context->cr3 = 0;
271271
cur_context->cr4 = CR4_VMXE;
272-
} else if (get_vcpu_mode(vcpu) == PAGE_PROTECTED_MODE) {
272+
} else if (get_vcpu_mode(vcpu) == CPU_MODE_64BIT) {
273273
cur_context->cr0 = ((uint64_t)CR0_PG | CR0_PE | CR0_NE);
274274
cur_context->cr4 = ((uint64_t)CR4_PSE | CR4_PAE | CR4_MCE | CR4_VMXE);
275275
cur_context->cr3 = vm->arch_vm.guest_init_pml4 | CR3_PWT;
@@ -303,7 +303,7 @@ static void init_guest_state(struct vcpu *vcpu)
303303
/***************************************************/
304304
/* Set Code Segment - CS */
305305
/***************************************************/
306-
if (get_vcpu_mode(vcpu) == REAL_MODE) {
306+
if (get_vcpu_mode(vcpu) == CPU_MODE_REAL) {
307307
/* AP is initialized with real mode
308308
* and CS value is left shift 8 bits from sipi vector;
309309
*/
@@ -343,15 +343,15 @@ static void init_guest_state(struct vcpu *vcpu)
343343
/***************************************************/
344344
/* Set up guest instruction pointer */
345345
field = VMX_GUEST_RIP;
346-
if (get_vcpu_mode(vcpu) == REAL_MODE)
346+
if (get_vcpu_mode(vcpu) == CPU_MODE_REAL)
347347
value32 = 0;
348348
else
349349
value32 = (uint32_t) ((uint64_t) vcpu->entry_addr & 0xFFFFFFFF);
350350

351351
pr_dbg("GUEST RIP on VMEntry %x ", value32);
352352
exec_vmwrite(field, value32);
353353

354-
if (get_vcpu_mode(vcpu) == PAGE_PROTECTED_MODE) {
354+
if (get_vcpu_mode(vcpu) == CPU_MODE_64BIT) {
355355
/* Set up guest stack pointer to 0 */
356356
field = VMX_GUEST_RSP;
357357
value32 = 0;
@@ -365,13 +365,13 @@ static void init_guest_state(struct vcpu *vcpu)
365365
/***************************************************/
366366

367367
/* GDTR - Global Descriptor Table */
368-
if (get_vcpu_mode(vcpu) == REAL_MODE) {
368+
if (get_vcpu_mode(vcpu) == CPU_MODE_REAL) {
369369
/* Base */
370370
base = 0;
371371

372372
/* Limit */
373373
limit = 0xFFFF;
374-
} else if (get_vcpu_mode(vcpu) == PAGE_PROTECTED_MODE) {
374+
} else if (get_vcpu_mode(vcpu) == CPU_MODE_64BIT) {
375375
descriptor_table gdtb = {0, 0};
376376

377377
/* Base *//* TODO: Should guest GDTB point to host GDTB ? */
@@ -400,13 +400,13 @@ static void init_guest_state(struct vcpu *vcpu)
400400
pr_dbg("VMX_GUEST_GDTR_LIMIT: 0x%x ", limit);
401401

402402
/* IDTR - Interrupt Descriptor Table */
403-
if (get_vcpu_mode(vcpu) == REAL_MODE) {
403+
if (get_vcpu_mode(vcpu) == CPU_MODE_REAL) {
404404
/* Base */
405405
base = 0;
406406

407407
/* Limit */
408408
limit = 0xFFFF;
409-
} else if (get_vcpu_mode(vcpu) == PAGE_PROTECTED_MODE) {
409+
} else if (get_vcpu_mode(vcpu) == CPU_MODE_64BIT) {
410410
descriptor_table idtb = {0, 0};
411411

412412
/* TODO: Should guest IDTR point to host IDTR ? */
@@ -444,11 +444,11 @@ static void init_guest_state(struct vcpu *vcpu)
444444
/* ES, CS, SS, DS, FS, GS */
445445
/***************************************************/
446446
data32_idx = 0x10;
447-
if (get_vcpu_mode(vcpu) == REAL_MODE) {
447+
if (get_vcpu_mode(vcpu) == CPU_MODE_REAL) {
448448
es = ss = ds = fs = gs = data32_idx;
449449
limit = 0xffff;
450450

451-
} else if (get_vcpu_mode(vcpu) == PAGE_PROTECTED_MODE) {
451+
} else if (get_vcpu_mode(vcpu) == CPU_MODE_64BIT) {
452452
asm volatile ("movw %%es, %%ax":"=a" (es));
453453
asm volatile ("movw %%ss, %%ax":"=a" (ss));
454454
asm volatile ("movw %%ds, %%ax":"=a" (ds));
@@ -496,9 +496,9 @@ static void init_guest_state(struct vcpu *vcpu)
496496
pr_dbg("VMX_GUEST_GS_LIMIT: 0x%x ", limit);
497497

498498
/* Access */
499-
if (get_vcpu_mode(vcpu) == REAL_MODE)
499+
if (get_vcpu_mode(vcpu) == CPU_MODE_REAL)
500500
value32 = 0x0093;
501-
else if (get_vcpu_mode(vcpu) == PAGE_PROTECTED_MODE)
501+
else if (get_vcpu_mode(vcpu) == CPU_MODE_64BIT)
502502
value32 = 0xc093;
503503

504504
field = VMX_GUEST_ES_ATTR;
@@ -609,7 +609,7 @@ static void init_guest_state(struct vcpu *vcpu)
609609
pr_dbg("VMX_GUEST_IA32_PAT: 0x%016llx ",
610610
value64);
611611

612-
if (get_vcpu_mode(vcpu) == REAL_MODE) {
612+
if (get_vcpu_mode(vcpu) == CPU_MODE_REAL) {
613613
/* Disable long mode (clear IA32_EFER.LME) in VMCS IA32_EFER
614614
* MSR
615615
*/
@@ -1024,7 +1024,7 @@ static void init_exec_ctrl(struct vcpu *vcpu)
10241024
fixed0 = msr_read(MSR_IA32_VMX_CR0_FIXED0);
10251025
fixed1 = msr_read(MSR_IA32_VMX_CR0_FIXED1);
10261026

1027-
if (get_vcpu_mode(vcpu) == REAL_MODE) {
1027+
if (get_vcpu_mode(vcpu) == CPU_MODE_REAL) {
10281028
/* Check to see if unrestricted guest support is available */
10291029
if (msr_read(MSR_IA32_VMX_MISC) & (1 << 5)) {
10301030
/* Adjust fixed bits as they can/will reflect incorrect
@@ -1047,7 +1047,7 @@ static void init_exec_ctrl(struct vcpu *vcpu)
10471047

10481048
}
10491049

1050-
/* (get_vcpu_mode(vcpu) == REAL_MODE) */
1050+
/* (get_vcpu_mode(vcpu) == CPU_MODE_REAL) */
10511051
/* Output fixed CR0 values */
10521052
pr_dbg("Fixed0 CR0 value: 0x%x", fixed0);
10531053
pr_dbg("Fixed1 CR0 value: 0x%x", fixed1);
@@ -1129,7 +1129,7 @@ static void init_entry_ctrl(__unused struct vcpu *vcpu)
11291129
* IA32_PAT and IA32_EFER
11301130
*/
11311131
value32 = msr_read(MSR_IA32_VMX_ENTRY_CTLS);
1132-
if (get_vcpu_mode(vcpu) == PAGE_PROTECTED_MODE)
1132+
if (get_vcpu_mode(vcpu) == CPU_MODE_64BIT)
11331133
value32 |= (VMX_ENTRY_CTLS_IA32E_MODE);
11341134

11351135
value32 |= (VMX_ENTRY_CTLS_LOAD_EFER |
@@ -1197,7 +1197,7 @@ static void override_uefi_vmcs(struct vcpu *vcpu)
11971197
struct run_context *cur_context =
11981198
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context];
11991199

1200-
if (get_vcpu_mode(vcpu) == PAGE_PROTECTED_MODE) {
1200+
if (get_vcpu_mode(vcpu) == CPU_MODE_64BIT) {
12011201
/* Set up guest CR0 field */
12021202
field = VMX_GUEST_CR0;
12031203
cur_context->cr0 = efi_ctx->cr0 | CR0_PG | CR0_PE | CR0_NE;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ struct vm_lu_mem_map {
9191
uint64_t size; /* Size of map */
9292
};
9393

94+
enum vm_cpu_mode {
95+
CPU_MODE_REAL,
96+
CPU_MODE_PROTECTED,
97+
CPU_MODE_COMPATIBILITY, /* IA-32E mode (CS.L = 0) */
98+
CPU_MODE_64BIT, /* IA-32E mode (CS.L = 1) */
99+
};
100+
101+
enum vm_paging_mode {
102+
PAGING_MODE_FLAT,
103+
PAGING_MODE_32,
104+
PAGING_MODE_PAE,
105+
PAGING_MODE_64,
106+
};
107+
94108
/*
95109
* VM related APIs
96110
*/

hypervisor/include/arch/x86/vmx.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,6 @@
453453
CR4_VMXE | CR4_SMXE | CR4_PGE | CR4_PCIDE)
454454
#define CR4_READ_SHADOW (CR4_PGE | CR4_PSE)
455455

456-
/* VCPU config definitions */
457-
#define REAL_MODE 1
458-
#define PAGE_PROTECTED_MODE 2
459-
460456
/* External Interfaces */
461457
int exec_vmxon_instr(void);
462458
uint64_t exec_vmread(uint32_t field);

0 commit comments

Comments
 (0)