Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add ROM device support
ROM device is read-only. Its read operation will pass through. Its
Write operation will be handled as MMIO. Don't dinguish ROM and ROM
device exactly as no side impact.

Signed-off-by: Hang Yuan <hang.yuan@intel.com>
  • Loading branch information
hyuan3 committed Jun 19, 2019
1 parent e3f02ce commit 33ceea0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
27 changes: 17 additions & 10 deletions core/ept2.c
Expand Up @@ -84,16 +84,6 @@ int ept_handle_access_violation(hax_gpa_space *gpa_space, hax_ept_tree *tree,
uint64_t start_gpa, size;
int ret;

// Extract bits 5..3 from Exit Qualification
combined_perm = (uint) ((qual.raw >> 3) & 7);
// See IA SDM Vol. 3C 27.2.1 Table 27-7, especially note 2
if (combined_perm != HAX_EPT_PERM_NONE) {
hax_error("%s: Cannot handle the case where the PTE corresponding to"
" the faulting GPA is present: qual=0x%llx, gpa=0x%llx\n",
__func__, qual.raw, gpa);
return -EACCES;
}

gfn = gpa >> PG_ORDER_4K;
hax_assert(gpa_space != NULL);
slot = memslot_find(gpa_space, gfn);
Expand All @@ -103,6 +93,23 @@ int ept_handle_access_violation(hax_gpa_space *gpa_space, hax_ept_tree *tree,
return 0;
}

// Extract bits 5..3 from Exit Qualification
combined_perm = (uint) ((qual.raw >> 3) & 7);
if (combined_perm != HAX_EPT_PERM_NONE) {
if ((qual.raw & HAX_EPT_ACC_W) && !(combined_perm & HAX_EPT_PERM_W) &&
(slot->flags == HAX_MEMSLOT_READONLY)) {
// Handle a write to ROM/ROM device as MMIO
hax_debug("%s: write to a read-only gpa=0x%llx\n",
__func__, gpa);
return 0;
}
// See IA SDM Vol. 3C 27.2.1 Table 27-7, especially note 2
hax_error("%s: Cannot handle the case where the PTE corresponding to"
" the faulting GPA is present: qual=0x%llx, gpa=0x%llx\n",
__func__, qual.raw, gpa);
return -EACCES;
}

// Ideally we should call gpa_space_is_page_protected() and ask user space
// to unprotect just the host virtual page that |gfn| maps to. But since we
// pin host RAM one chunk (rather than one page) at a time, if the chunk
Expand Down
5 changes: 5 additions & 0 deletions core/include/ept2.h
Expand Up @@ -45,9 +45,14 @@
#define HAX_EPT_TABLE_SHIFT 9
#define HAX_EPT_TABLE_SIZE (1 << HAX_EPT_TABLE_SHIFT)

#define HAX_EPT_ACC_R 0x1
#define HAX_EPT_ACC_W 0x2
#define HAX_EPT_ACC_X 0x4

#define HAX_EPT_PERM_NONE 0x0
#define HAX_EPT_PERM_RWX 0x7
#define HAX_EPT_PERM_RX 0x5
#define HAX_EPT_PERM_W 0x2

#define HAX_EPT_MEMTYPE_UC 0x0
#define HAX_EPT_MEMTYPE_WB 0x6
Expand Down

0 comments on commit 33ceea0

Please sign in to comment.