hv: add API to get vcpu paging mode

Use # of paging level to identify paging mode

Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
Acked-by: Xu, Anthony <anthony.xu@intel.com>
This commit is contained in:
Binbin Wu 2018-05-15 12:04:49 +08:00 committed by lijinxia
parent fb09f9daca
commit dd14d8e1b0
3 changed files with 29 additions and 5 deletions

View File

@ -153,6 +153,26 @@ int copy_to_vm(struct vm *vm, void *h_ptr, uint64_t gpa, uint32_t size)
return 0;
}
enum vm_paging_mode get_vcpu_paging_mode(struct vcpu *vcpu)
{
struct run_context *cur_context =
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context];
enum vm_cpu_mode cpu_mode;
cpu_mode = get_vcpu_mode(vcpu);
if (cpu_mode == CPU_MODE_REAL)
return PAGING_MODE_0_LEVEL;
else if (cpu_mode == CPU_MODE_PROTECTED) {
if (cur_context->cr4 & CR4_PAE)
return PAGING_MODE_3_LEVEL;
else if (cur_context->cr0 & CR0_PG)
return PAGING_MODE_2_LEVEL;
return PAGING_MODE_0_LEVEL;
} else /* compatibility or 64bit mode */
return PAGING_MODE_4_LEVEL;
}
uint64_t gva2gpa(struct vm *vm, uint64_t cr3, uint64_t gva)
{
int level, index, shift;

View File

@ -281,7 +281,7 @@ static void get_guest_paging_info(struct vcpu *vcpu, struct emul_cnx *emul_cnx)
vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].cr3;
emul_cnx->paging.cpl = cpl;
emul_cnx->paging.cpu_mode = get_vcpu_mode(vcpu);
emul_cnx->paging.paging_mode = PAGING_MODE_FLAT;/*maybe change later*/
emul_cnx->paging.paging_mode = get_vcpu_paging_mode(vcpu);
}
static int mmio_read(struct vcpu *vcpu, __unused uint64_t gpa, uint64_t *rval,

View File

@ -75,11 +75,13 @@ enum vm_cpu_mode {
CPU_MODE_64BIT, /* IA-32E mode (CS.L = 1) */
};
/* Use # of paging level to identify paging mode */
enum vm_paging_mode {
PAGING_MODE_FLAT,
PAGING_MODE_32,
PAGING_MODE_PAE,
PAGING_MODE_64,
PAGING_MODE_0_LEVEL = 0, /* Flat */
PAGING_MODE_2_LEVEL = 2, /* 32bit paging, 2-level */
PAGING_MODE_3_LEVEL = 3, /* PAE paging, 3-level */
PAGING_MODE_4_LEVEL = 4, /* 64bit paging, 4-level */
PAGING_MODE_NUM,
};
/*
@ -96,6 +98,8 @@ struct vcpu *get_primary_vcpu(struct vm *vm);
struct vcpu *vcpu_from_vid(struct vm *vm, int vcpu_id);
struct vcpu *vcpu_from_pid(struct vm *vm, int pcpu_id);
enum vm_paging_mode get_vcpu_paging_mode(struct vcpu *vcpu);
void init_e820(void);
void obtain_e820_mem_info(void);
extern uint32_t e820_entries;