Skip to content

Commit 4a22801

Browse files
binbinwu1acrnsi
authored andcommitted
hv: ept: mask EPT leaf entry bit 52 to bit 63 in gpa2hpa
According to SDM, bit N (physical address width) to bit 63 should be masked when calculate host page frame number. Currently, hypervisor doesn't set any of these bits, so gpa2hpa can work as expectd. However, any of these bit set, gpa2hpa return wrong value. Hypervisor never sets bit N to bit 51 (reserved bits), for simplicity, just mask bit 52 to bit 63. Tracked-On: #3352 Signed-off-by: Binbin Wu <binbin.wu@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com>
1 parent c64877f commit 4a22801

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

hypervisor/arch/x86/guest/ept.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ uint64_t local_gpa2hpa(struct acrn_vm *vm, uint64_t gpa, uint32_t *size)
4444
eptp = get_ept_entry(vm);
4545
pgentry = lookup_address((uint64_t *)eptp, gpa, &pg_size, &vm->arch_vm.ept_mem_ops);
4646
if (pgentry != NULL) {
47-
hpa = ((*pgentry & (~(pg_size - 1UL)))
47+
hpa = (((*pgentry & (~EPT_PFN_HIGH_MASK)) & (~(pg_size - 1UL)))
4848
| (gpa & (pg_size - 1UL)));
4949
}
5050

hypervisor/include/arch/x86/pgtable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
/* VTD: Second-Level Paging Entries: Snoop Control */
112112
#define EPT_SNOOP_CTRL (1UL << 11U)
113113
#define EPT_VE (1UL << 63U)
114+
/* EPT leaf entry bits (bit 52 - bit 63) should be maksed when calculate PFN */
115+
#define EPT_PFN_HIGH_MASK 0xFFF0000000000000UL
114116

115117
#define PML4E_SHIFT 39U
116118
#define PTRS_PER_PML4E 512UL

0 commit comments

Comments
 (0)