Skip to content

Commit

Permalink
hv: mmu: add some API for guest page mode check
Browse files Browse the repository at this point in the history
add is_long_mode to check whether the processor is operating in IA-32e mode
add is_paging_enabled to check whether paging is enabled
add is_pae to check whether physical address extension is enabled.

Tracked-On: #1379
Signed-off-by: Li, Fei1 <fei1.li@intel.com>
  • Loading branch information
lifeix authored and wenlingz committed Oct 10, 2018
1 parent 9fd8781 commit 2b24b37
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions hypervisor/arch/x86/guest/guest.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ enum vm_paging_mode get_vcpu_paging_mode(struct vcpu *vcpu)
return PAGING_MODE_0_LEVEL;
}
else if (cpu_mode == CPU_MODE_PROTECTED) {
if ((vcpu_get_cr4(vcpu) & CR4_PAE) != 0U) {
if (is_pae(vcpu)) {
return PAGING_MODE_3_LEVEL;
}
else if ((vcpu_get_cr0(vcpu) & CR0_PG) != 0U) {
else if (is_paging_enabled(vcpu)) {
return PAGING_MODE_2_LEVEL;
}
return PAGING_MODE_0_LEVEL;
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/arch/x86/guest/vcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)

static void set_vcpu_mode(struct vcpu *vcpu, uint32_t cs_attr)
{
if (vcpu_get_efer(vcpu) & MSR_IA32_EFER_LMA_BIT) {
if (is_long_mode(vcpu)) {
if (cs_attr & 0x2000) /* CS.L = 1 */
vcpu->arch_vcpu.cpu_mode = CPU_MODE_64BIT;
else
Expand Down
4 changes: 2 additions & 2 deletions hypervisor/arch/x86/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static bool is_cr0_write_valid(struct vcpu *vcpu, uint64_t cr0)
* CR0.PG = 1, CR4.PAE = 0 and IA32_EFER.LME = 1 is invalid.
* CR0.PE = 0 and CR0.PG = 1 is invalid.
*/
if (((cr0 & CR0_PG) != 0UL) && ((vcpu_get_cr4(vcpu) & CR4_PAE) == 0UL)
if (((cr0 & CR0_PG) != 0UL) && !is_pae(vcpu)
&& ((vcpu_get_efer(vcpu) & MSR_IA32_EFER_LME_BIT) != 0UL))
return false;

Expand Down Expand Up @@ -348,7 +348,7 @@ void vmx_write_cr0(struct vcpu *vcpu, uint64_t cr0)
{
uint64_t cr0_vmx;
uint32_t entry_ctrls;
bool paging_enabled = !!(vcpu_get_cr0(vcpu) & CR0_PG);
bool paging_enabled = is_paging_enabled(vcpu);

if (!is_cr0_write_valid(vcpu, cr0)) {
pr_dbg("Invalid cr0 write operation from guest");
Expand Down
15 changes: 15 additions & 0 deletions hypervisor/include/arch/x86/guest/vcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,21 @@ uint64_t vcpu_get_pat_ext(struct vcpu *vcpu);
void vcpu_set_pat_ext(struct vcpu *vcpu, uint64_t val);
void set_vcpu_regs(struct vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs);

static inline bool is_long_mode(struct vcpu *vcpu)
{
return (vcpu_get_efer(vcpu) & MSR_IA32_EFER_LMA_BIT) != 0UL;
}

static inline bool is_paging_enabled(struct vcpu *vcpu)
{
return (vcpu_get_cr0(vcpu) & CR0_PG) != 0UL;
}

static inline bool is_pae(struct vcpu *vcpu)
{
return (vcpu_get_cr4(vcpu) & CR4_PAE) != 0UL;
}

struct vcpu* get_ever_run_vcpu(uint16_t pcpu_id);
int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle);
int run_vcpu(struct vcpu *vcpu);
Expand Down

0 comments on commit 2b24b37

Please sign in to comment.