vm_session: extensions

- support to create multiple vCPUs
- support to implement Vm_session methods client side within base library
- adjust muen specific virtualbox4 version to compile/link

Issue #3111
This commit is contained in:
Alexander Boettcher
2018-09-26 15:53:18 +02:00
committed by Norman Feske
parent c5786b212b
commit 0c24e1efdc
28 changed files with 403 additions and 157 deletions

View File

@@ -0,0 +1,85 @@
/*
* \brief CPU, PIC, and timer context of a virtual machine
* \author Stefan Kalkowski
* \date 2015-02-10
*/
/*
* Copyright (C) 2015-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__SPEC__ARNDALE__VM_STATE_H_
#define _INCLUDE__SPEC__ARNDALE__VM_STATE_H_
/* Genode includes */
#include <cpu/cpu_state.h>
namespace Genode
{
/**
* CPU context of a virtual machine
*/
struct Vm_state;
}
struct Genode::Vm_state : Genode::Cpu_state_modes
{
Genode::uint64_t vttbr;
Genode::uint32_t sctrl;
Genode::uint32_t hsr;
Genode::uint32_t hpfar;
Genode::uint32_t hdfar;
Genode::uint32_t hifar;
Genode::uint32_t ttbcr;
Genode::uint32_t ttbr0;
Genode::uint32_t ttbr1;
Genode::uint32_t prrr;
Genode::uint32_t nmrr;
Genode::uint32_t dacr;
Genode::uint32_t dfsr;
Genode::uint32_t ifsr;
Genode::uint32_t adfsr;
Genode::uint32_t aifsr;
Genode::uint32_t dfar;
Genode::uint32_t ifar;
Genode::uint32_t cidr;
Genode::uint32_t tls1;
Genode::uint32_t tls2;
Genode::uint32_t tls3;
Genode::uint32_t cpacr;
/**
* Fpu registers
*/
Genode::uint32_t fpscr;
Genode::uint64_t d0_d31[32];
/**
* Timer related registers
*/
Genode::uint32_t timer_ctrl;
Genode::uint32_t timer_val;
bool timer_irq;
/**
* PIC related registers
*/
enum { NR_IRQ = 4 };
Genode::uint32_t gic_hcr;
Genode::uint32_t gic_vmcr;
Genode::uint32_t gic_misr;
Genode::uint32_t gic_apr;
Genode::uint32_t gic_eisr;
Genode::uint32_t gic_elrsr0;
Genode::uint32_t gic_lr[4];
unsigned gic_irq;
};
#endif /* _INCLUDE__SPEC__ARNDALE__VM_STATE_H_ */

View File

@@ -16,9 +16,10 @@
/* Genode includes */
#include <vm_session/capability.h>
#include <vm_session/handler.h>
#include <base/rpc_client.h>
namespace Genode { struct Vm_session_client; }
namespace Genode { struct Vm_session_client; class Allocator; class Vm_state; }
/**
* Client-side VM session interface
@@ -36,14 +37,10 @@ struct Genode::Vm_session_client : Rpc_client<Vm_session>
** Vm_session interface **
**************************/
Dataspace_capability cpu_state() {
return call<Rpc_cpu_state>(); }
Dataspace_capability cpu_state(Vcpu_id);
void exception_handler(Signal_context_capability handler) {
call<Rpc_exception_handler>(handler); }
void run() { call<Rpc_run>(); }
void pause() { call<Rpc_pause>(); }
void run(Vcpu_id);
void pause(Vcpu_id);
void attach(Dataspace_capability ds,addr_t vm_addr) {
call<Rpc_attach>(ds, vm_addr); }
@@ -53,6 +50,8 @@ struct Genode::Vm_session_client : Rpc_client<Vm_session>
void attach_pic(addr_t vm_addr) {
call<Rpc_attach_pic>(vm_addr); }
Vcpu_id create_vcpu(Allocator &, Env &, Vm_handler_base &);
};
#endif /* _INCLUDE__VM_SESSION__CLIENT_H_ */

View File

@@ -14,6 +14,7 @@
#ifndef _INCLUDE__VM_SESSION__CONNECTION_H_
#define _INCLUDE__VM_SESSION__CONNECTION_H_
#include <util/retry.h>
#include <vm_session/client.h>
#include <cpu_session/cpu_session.h>
#include <base/connection.h>
@@ -65,6 +66,19 @@ struct Genode::Vm_connection : Connection<Vm_session>, Vm_session_client
Connection<Vm_session>(_session(*env_deprecated()->parent(), label, priority, affinity)),
Vm_session_client(cap())
{ }
template <typename FUNC>
auto with_upgrade(FUNC func) -> decltype(func())
{
return Genode::retry<Genode::Out_of_ram>(
[&] () {
return Genode::retry<Genode::Out_of_caps>(
[&] () { return func(); },
[&] () { this->upgrade_caps(2); });
},
[&] () { this->upgrade_ram(4096); }
);
}
};
#endif /* _INCLUDE__VM_SESSION__CONNECTION_H_ */

View File

@@ -0,0 +1,103 @@
/*
* \brief Client-side VM session exception handler
* \author Alexander Boettcher
* \date 2018-09-29
*/
/*
* Copyright (C) 2018 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__VM_SESSION__HANDLER_H_
#define _INCLUDE__VM_SESSION__HANDLER_H_
#include <base/signal.h>
namespace Genode {
class Vm_state;
class Vm_handler_base;
template <typename, typename> class Vm_handler;
}
class Genode::Vm_handler_base : public Signal_dispatcher_base
{
friend class Vm_session_client;
protected:
Rpc_entrypoint &_rpc_ep;
Signal_context_capability _cap {};
Genode::Semaphore _done { 0 };
public:
virtual bool config_vm_event(Genode::Vm_state &, unsigned) = 0;
Vm_handler_base(Rpc_entrypoint &rpc)
: _rpc_ep(rpc) { }
};
template <typename T, typename EP = Genode::Entrypoint>
class Genode::Vm_handler : public Vm_handler_base
{
private:
EP &_ep;
T &_obj;
void (T::*_member) ();
void (T::*_config) (Genode::Vm_state &, unsigned const);
/*
* Noncopyable
*/
Vm_handler(Vm_handler const &);
Vm_handler &operator = (Vm_handler const &);
public:
/**
* Constructor
*
* \param obj,member object and method to call when
* the vm exception occurs
*/
Vm_handler(EP &ep, T &obj, void (T::*member)(),
void (T::*config)(Genode::Vm_state&, unsigned) = nullptr)
:
Vm_handler_base(ep.rpc_ep()),
_ep(ep),
_obj(obj),
_member(member),
_config(config)
{
_cap = ep.manage(*this);
}
~Vm_handler() { _ep.dissolve(*this); }
/**
* Interface of Signal_dispatcher_base
*/
void dispatch(unsigned) override
{
(_obj.*_member)();
_done.up();
}
bool config_vm_event(Genode::Vm_state &state,
unsigned const vm_event) override
{
if (!_config)
return false;
(_obj.*_config)(state, vm_event);
return true;
}
operator Capability<Signal_context>() const { return _cap; }
};
#endif /* _INCLUDE__VM_SESSION__HANDLER_H_ */

View File

@@ -26,6 +26,8 @@ struct Genode::Vm_session : Session
{
static const char *service_name() { return "VM"; }
struct Vcpu_id { unsigned id; };
enum { CAP_QUOTA = 3 };
class Invalid_dataspace : Exception { };
@@ -35,26 +37,6 @@ struct Genode::Vm_session : Session
*/
virtual ~Vm_session() { }
/**
* Get dataspace of the CPU state of the VM
*/
virtual Dataspace_capability cpu_state(void) = 0;
/**
* Register signal handler for exceptions of the Vm
*/
virtual void exception_handler(Signal_context_capability handler) = 0;
/**
* (Re-)Start execution of the VM
*/
virtual void run(void) {}
/**
* Stop execution of the VM
*/
virtual void pause(void) {}
/**
* Attach dataspace to the guest-physical memory address space
*
@@ -82,24 +64,27 @@ struct Genode::Vm_session : Session
*/
virtual void attach_pic(addr_t vm_addr) = 0;
/*********************
** RPC declaration **
*********************/
GENODE_RPC(Rpc_cpu_state, Dataspace_capability, cpu_state);
GENODE_RPC(Rpc_exception_handler, void, exception_handler,
Signal_context_capability);
GENODE_RPC(Rpc_run, void, run);
GENODE_RPC(Rpc_pause, void, pause);
GENODE_RPC(Rpc_cpu_state, Dataspace_capability, _cpu_state, Vcpu_id);
GENODE_RPC(Rpc_exception_handler, void, _exception_handler,
Signal_context_capability, Vcpu_id);
GENODE_RPC(Rpc_run, void, _run, Vcpu_id);
GENODE_RPC(Rpc_pause, void, _pause, Vcpu_id);
GENODE_RPC_THROW(Rpc_attach, void, attach,
GENODE_TYPE_LIST(Invalid_dataspace),
Dataspace_capability, addr_t);
GENODE_RPC(Rpc_detach, void, detach, addr_t, size_t);
GENODE_RPC(Rpc_attach_pic, void, attach_pic, addr_t);
GENODE_RPC_THROW(Rpc_create_vcpu, void, _create_vcpu,
GENODE_TYPE_LIST(Out_of_ram, Out_of_caps),
Thread_capability);
GENODE_RPC_INTERFACE(Rpc_cpu_state, Rpc_exception_handler,
Rpc_run, Rpc_pause, Rpc_attach, Rpc_detach,
Rpc_attach_pic);
Rpc_attach_pic, Rpc_create_vcpu);
};
#endif /* _INCLUDE__VM_SESSION__VM_SESSION_H_ */