From 63591160df764bf1087a9c0d90b02f83ad1b5ba1 Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Tue, 10 May 2016 22:56:40 +0200 Subject: [PATCH] vbox: Factor out memory config check Move Genode/vbox memory configuration check to separate genode_check_memory_config() function and call it in platform-specific setup machine hook of accloff/nova. The rationale for this change is to omit the check on Muen since the guest memory is separate and not allocated from base-hw memory. Issue #2016 --- repos/ports/src/virtualbox/accloff/sup.cc | 5 +++- repos/ports/src/virtualbox/frontend/main.cc | 21 ---------------- repos/ports/src/virtualbox/spec/nova/sup.cc | 5 +++- repos/ports/src/virtualbox/sup.cc | 28 +++++++++++++++++++++ repos/ports/src/virtualbox/sup.h | 2 ++ 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/repos/ports/src/virtualbox/accloff/sup.cc b/repos/ports/src/virtualbox/accloff/sup.cc index 1582ba3206..295ead2fbd 100644 --- a/repos/ports/src/virtualbox/accloff/sup.cc +++ b/repos/ports/src/virtualbox/accloff/sup.cc @@ -123,7 +123,10 @@ void genode_update_tsc(void (*update_func)(void), unsigned long update_us) } -HRESULT genode_setup_machine(ComObjPtr machine) { return S_OK; } +HRESULT genode_setup_machine(ComObjPtr machine) +{ + return genode_check_memory_config(machine); +} bool Vmm_memory::revoke_from_vm(Mem_region *r) diff --git a/repos/ports/src/virtualbox/frontend/main.cc b/repos/ports/src/virtualbox/frontend/main.cc index 2b54fa33f8..4f05362c30 100644 --- a/repos/ports/src/virtualbox/frontend/main.cc +++ b/repos/ports/src/virtualbox/frontend/main.cc @@ -125,27 +125,6 @@ HRESULT setupmachine() if (FAILED(rc)) return rc; - /* Validate configured memory of vbox file and Genode config */ - ULONG memory_vbox; - rc = machine->COMGETTER(MemorySize)(&memory_vbox); - if (FAILED(rc)) - return rc; - - /* request max available memory */ - size_t memory_genode = Genode::env()->ram_session()->avail() >> 20; - size_t memory_vmm = 28; - - if (memory_vbox + memory_vmm > memory_genode) { - PERR("Configured memory %u MB (vbox file) is insufficient.", - memory_vbox); - PERR("%zu MB (1) - %zu MB (2) = %zu MB (3)", - memory_genode, memory_vmm, memory_genode - memory_vmm); - PERR("(1) available memory based defined by Genode config"); - PERR("(2) minimum memory required for VBox VMM"); - PERR("(3) maximal available memory to VM"); - return E_FAIL; - } - /* Console object */ ComPtr gConsole; rc = session->COMGETTER(Console)(gConsole.asOutParam()); diff --git a/repos/ports/src/virtualbox/spec/nova/sup.cc b/repos/ports/src/virtualbox/spec/nova/sup.cc index e46b8833cd..ad633a24f5 100644 --- a/repos/ports/src/virtualbox/spec/nova/sup.cc +++ b/repos/ports/src/virtualbox/spec/nova/sup.cc @@ -216,7 +216,10 @@ void genode_update_tsc(void (*update_func)(void), unsigned long update_us) } -HRESULT genode_setup_machine(ComObjPtr machine) { return S_OK; } +HRESULT genode_setup_machine(ComObjPtr machine) +{ + return genode_check_memory_config(machine); +}; bool Vmm_memory::revoke_from_vm(Mem_region *r) diff --git a/repos/ports/src/virtualbox/sup.cc b/repos/ports/src/virtualbox/sup.cc index 59e60a4252..1730d2c1e7 100644 --- a/repos/ports/src/virtualbox/sup.cc +++ b/repos/ports/src/virtualbox/sup.cc @@ -328,3 +328,31 @@ void genode_VMMR0_DO_GVMM_REGISTER_VMCPU(PVMR0 pVMR0, VMCPUID idCpu) PVM pVM = reinterpret_cast(pVMR0); pVM->aCpus[idCpu].hNativeThreadR0 = RTThreadNativeSelf(); } + + +HRESULT genode_check_memory_config(ComObjPtr machine) +{ + HRESULT rc; + + /* Validate configured memory of vbox file and Genode config */ + ULONG memory_vbox; + rc = machine->COMGETTER(MemorySize)(&memory_vbox); + if (FAILED(rc)) + return rc; + + /* Request max available memory */ + size_t memory_genode = Genode::env()->ram_session()->avail() >> 20; + size_t memory_vmm = 28; + + if (memory_vbox + memory_vmm > memory_genode) { + PERR("Configured memory %u MB (vbox file) is insufficient.", + memory_vbox); + PERR("%zu MB (1) - %zu MB (2) = %zu MB (3)", + memory_genode, memory_vmm, memory_genode - memory_vmm); + PERR("(1) available memory based defined by Genode config"); + PERR("(2) minimum memory required for VBox VMM"); + PERR("(3) maximal available memory to VM"); + return E_FAIL; + } + return S_OK; +} diff --git a/repos/ports/src/virtualbox/sup.h b/repos/ports/src/virtualbox/sup.h index c0c68b8916..409b73232d 100644 --- a/repos/ports/src/virtualbox/sup.h +++ b/repos/ports/src/virtualbox/sup.h @@ -47,4 +47,6 @@ void genode_VMMR0_DO_GVMM_REGISTER_VMCPU(PVMR0 pVMR0, VMCPUID idCpu); HRESULT genode_setup_machine(ComObjPtr machine); +HRESULT genode_check_memory_config(ComObjPtr machine); + #endif /* _SUP_H_ */