Skip to content

Commit

Permalink
[lib][hypervisor] Traps outside of mapped memory
Browse files Browse the repository at this point in the history
Allow traps to be set that are outside of mapped memory. This will
return success if attempt to set a trap that straddles mappings, but the
trap will not operate correctly in that situation.

Test: Ran "k ut hypervisor".
Change-Id: I0c8a70b9d9564b5892eb96b71c9798d86de9deb6
  • Loading branch information
abdulla authored and CQ bot account: [email protected] committed Aug 10, 2018
1 parent c37328e commit 178322b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kernel/lib/hypervisor/guest_physical_address_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ zx_status_t GuestPhysicalAddressSpace::MapInterruptController(zx_gpaddr_t guest_
}

zx_status_t GuestPhysicalAddressSpace::UnmapRange(zx_gpaddr_t guest_paddr, size_t len) {
return RootVmar()->Unmap(guest_paddr, len);
zx_status_t status = RootVmar()->Unmap(guest_paddr, len);
if (status == ZX_ERR_INVALID_ARGS) {
return ZX_OK;
}
return status;
}

zx_status_t GuestPhysicalAddressSpace::GetPage(zx_gpaddr_t guest_paddr, zx_paddr_t* host_paddr) {
Expand Down
23 changes: 23 additions & 0 deletions kernel/lib/hypervisor/hypervisor_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@ static bool guest_physical_address_space_unmap_range() {
END_TEST;
}

static bool guest_physical_address_space_unmap_range_outside_of_mapping() {
BEGIN_TEST;

if (!hypervisor_supported()) {
return true;
}

// Setup.
fbl::RefPtr<VmObject> vmo;
zx_status_t status = create_vmo(PAGE_SIZE, &vmo);
EXPECT_EQ(ZX_OK, status, "Failed to setup VMO.\n");
fbl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
status = create_gpas(vmo, &gpas);
EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace.\n");

// Unmap page.
status = gpas->UnmapRange(PAGE_SIZE * 8, PAGE_SIZE);
EXPECT_EQ(ZX_OK, status, "Failed to unmap page from GuestPhysicalAddressSpace.\n");

END_TEST;
}

static bool guest_physical_address_space_get_page_not_present() {
BEGIN_TEST;

Expand Down Expand Up @@ -339,6 +361,7 @@ static bool guest_physical_address_space_write_combining() {

UNITTEST_START_TESTCASE(hypervisor)
HYPERVISOR_UNITTEST(guest_physical_address_space_unmap_range)
HYPERVISOR_UNITTEST(guest_physical_address_space_unmap_range_outside_of_mapping)
HYPERVISOR_UNITTEST(guest_physical_address_space_get_page)
HYPERVISOR_UNITTEST(guest_physical_address_space_get_page_complex)
HYPERVISOR_UNITTEST(guest_physical_address_space_get_page_not_present)
Expand Down

0 comments on commit 178322b

Please sign in to comment.