From 597f7658fc4b3c9611b07c373286741552a5a199 Mon Sep 17 00:00:00 2001 From: Binbin Wu Date: Fri, 10 Apr 2020 09:36:46 +0000 Subject: [PATCH] hv: guest: fix bug in get_vcpu_paging_mode Align the implementation to SDM Vol.3 4.1.1. Also this patch fixed a bug that doesn't check paging status first in some cpu mode. Tracked-On: #4628 Signed-off-by: Binbin Wu Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/guest_memory.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/hypervisor/arch/x86/guest/guest_memory.c b/hypervisor/arch/x86/guest/guest_memory.c index c3a217009..3cb950a9f 100644 --- a/hypervisor/arch/x86/guest/guest_memory.c +++ b/hypervisor/arch/x86/guest/guest_memory.c @@ -33,24 +33,18 @@ struct page_walk_info { enum vm_paging_mode get_vcpu_paging_mode(struct acrn_vcpu *vcpu) { - enum vm_cpu_mode cpu_mode; - enum vm_paging_mode ret; + enum vm_paging_mode ret = PAGING_MODE_0_LEVEL; /* non-paging */ - cpu_mode = get_vcpu_mode(vcpu); - - if (cpu_mode == CPU_MODE_REAL) { - ret = PAGING_MODE_0_LEVEL; - - } else if (cpu_mode == CPU_MODE_PROTECTED) { + if (is_paging_enabled(vcpu)) { if (is_pae(vcpu)) { - ret = PAGING_MODE_3_LEVEL; - } else if (is_paging_enabled(vcpu)) { - ret = PAGING_MODE_2_LEVEL; + if (is_long_mode(vcpu)) { + ret = PAGING_MODE_4_LEVEL; /* 4-level paging */ + } else { + ret = PAGING_MODE_3_LEVEL; /* PAE paging */ + } } else { - ret = PAGING_MODE_0_LEVEL; + ret = PAGING_MODE_2_LEVEL; /* 32-bit paging */ } - } else { /* compatibility or 64bit mode */ - ret = PAGING_MODE_4_LEVEL; } return ret;