diff --git a/repos/ports/src/virtualbox6/nem.cc b/repos/ports/src/virtualbox6/nem.cc index 77a9b2b0d0..4697d35808 100644 --- a/repos/ports/src/virtualbox6/nem.cc +++ b/repos/ports/src/virtualbox6/nem.cc @@ -28,6 +28,9 @@ #include #include +/* Genode includes */ +#include + /* local includes */ #include #include @@ -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 }; diff --git a/repos/ports/src/virtualbox6/sup_gmm.cc b/repos/ports/src/virtualbox6/sup_gmm.cc index 5aab1427f7..ae223c5063 100644 --- a/repos/ports/src/virtualbox6/sup_gmm.cc +++ b/repos/ports/src/virtualbox6/sup_gmm.cc @@ -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); diff --git a/repos/ports/src/virtualbox6/sup_gmm.h b/repos/ports/src/virtualbox6/sup_gmm.h index 337aa8a613..12cb754cac 100644 --- a/repos/ports/src/virtualbox6/sup_gmm.h +++ b/repos/ports/src/virtualbox6/sup_gmm.h @@ -18,6 +18,7 @@ /* Genode includes */ #include #include +#include #include #include #include @@ -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 */