vbox6: synchronize guest-memory handling

This commit is contained in:
Christian Helmuth 2021-03-31 11:26:59 +02:00 committed by Norman Feske
parent ae8050bb82
commit 9ac23a18d4
3 changed files with 30 additions and 2 deletions

View File

@ -28,6 +28,9 @@
#include <VBox/vmm/em.h>
#include <VBox/err.h>
/* Genode includes */
#include <base/mutex.h>
/* local includes */
#include <stub_macros.h>
#include <sup.h>
@ -104,10 +107,11 @@ struct Sup::Nem
}
};
Mutex mutex { };
Range host_range { };
Range guest_range { };
void commit_range()
void commit_range_unsynchronized()
{
/* ignore commit of invalid ranges */
if (!host_range.valid())
@ -124,8 +128,17 @@ struct Sup::Nem
guest_range = { };
}
void commit_range()
{
Mutex::Guard guard(mutex);
commit_range_unsynchronized();
}
void map_to_guest(addr_t host_addr, addr_t guest_addr, size_t size, Protection prot)
{
Mutex::Guard guard(mutex);
Range new_host_range { host_addr, host_addr + (size - 1), prot };
Range new_guest_range { guest_addr, guest_addr + (size - 1), prot };
@ -144,7 +157,7 @@ struct Sup::Nem
}
/* new page starts a new range */
commit_range();
commit_range_unsynchronized();
/* start over with new page */
host_range = { host_addr, host_addr + (size - 1), prot };

View File

@ -95,6 +95,8 @@ Sup::Gmm::Vmm_addr Sup::Gmm::_alloc_pages(Pages pages)
void Sup::Gmm::reservation_pages(Pages pages)
{
Mutex::Guard guard(_mutex);
_reservation_pages = pages;
_update_pool_size();
@ -103,6 +105,8 @@ void Sup::Gmm::reservation_pages(Pages pages)
Sup::Gmm::Vmm_addr Sup::Gmm::alloc_ex(Pages pages)
{
Mutex::Guard guard(_mutex);
_alloc_ex_pages = { _alloc_ex_pages.value + pages.value };
_update_pool_size();
@ -113,12 +117,16 @@ Sup::Gmm::Vmm_addr Sup::Gmm::alloc_ex(Pages pages)
Sup::Gmm::Vmm_addr Sup::Gmm::alloc_from_reservation(Pages pages)
{
Mutex::Guard guard(_mutex);
return _alloc_pages(pages);
}
Sup::Gmm::Page_id Sup::Gmm::page_id(Vmm_addr addr)
{
Mutex::Guard guard(_mutex);
bool const inside_map = (addr.value >= _map.base.value)
&& (addr.value <= _map.end.value);
@ -143,6 +151,8 @@ uint32_t Sup::Gmm::page_id_as_uint32(Page_id page_id)
Sup::Gmm::Vmm_addr Sup::Gmm::vmm_addr(Page_id page_id)
{
Mutex::Guard guard(_mutex);
/* NIL_GMM_CHUNKID kept unused - so offset 0 is chunk ID 1 */
addr_t const addr = _map.base.value
+ ((page_id.value - (1u << GMM_CHUNKID_SHIFT)) << PAGE_SHIFT);
@ -159,6 +169,8 @@ Sup::Gmm::Vmm_addr Sup::Gmm::vmm_addr(Page_id page_id)
void Sup::Gmm::map_to_guest(Vmm_addr from, Guest_addr to, Pages pages, Protection prot)
{
Mutex::Guard guard(_mutex);
/* revoke existing mappings to avoid overmap */
_vm_connection.detach(to.value, pages.value << PAGE_SHIFT);

View File

@ -18,6 +18,7 @@
/* Genode includes */
#include <base/allocator_avl.h>
#include <base/attached_dataspace.h>
#include <base/mutex.h>
#include <rm_session/connection.h>
#include <vm_session/connection.h>
#include <region_map/client.h>
@ -93,6 +94,8 @@ class Sup::Gmm
static constexpr Bytes _map_size { 32*1024*1024*1024ul };
static constexpr auto _num_slices { _map_size.value / _slice_size.value };
Mutex _mutex { };
Dataspace_capability _slices[_num_slices];
Pages _size_pages { 0 }; /* current backing-store allocations */