vm_session: return vcpu id when creating vcpu

Ref #3553
This commit is contained in:
Stefan Kalkowski
2019-11-08 13:47:35 +01:00
committed by Norman Feske
parent 02d68fdb97
commit f82714f341
14 changed files with 63 additions and 55 deletions

View File

@@ -78,6 +78,7 @@ class Genode::Vm_session_component
addr_t new_pt_id();
Vcpu_id id() { return _id; }
bool match(Vcpu_id const id) const { return id.id == _id.id; }
Ram_dataspace_capability ds_cap() const { return _ds_cap; }
@@ -180,7 +181,7 @@ class Genode::Vm_session_component
void attach(Dataspace_capability, addr_t, Attach_attr) override;
void attach_pic(addr_t) override {}
void detach(addr_t, size_t) override;
void _create_vcpu(Thread_capability);
Vcpu_id _create_vcpu(Thread_capability);
};
#endif /* _CORE__VM_SESSION_COMPONENT_H_ */

View File

@@ -33,6 +33,7 @@
using Genode::addr_t;
using Genode::Vm_session_component;
using Vcpu_id = Genode::Vm_session::Vcpu_id;
enum { CAP_RANGE_LOG2 = 2, CAP_RANGE = 1 << CAP_RANGE_LOG2 };
@@ -153,10 +154,10 @@ static Genode::uint8_t _with_kernel_quota_upgrade(addr_t const pd_target,
return res;
}
void Vm_session_component::_create_vcpu(Thread_capability cap)
Vcpu_id Vm_session_component::_create_vcpu(Thread_capability cap)
{
if (!cap.valid())
return;
Vcpu_id ret;
if (!cap.valid()) return ret;
/* lookup vmm pd and cpu location of handler thread in VMM */
addr_t kernel_cpu_id = 0;
@@ -178,7 +179,7 @@ void Vm_session_component::_create_vcpu(Thread_capability cap)
/* if VMM pd lookup failed then deny to create vCPU */
if (!vmm_pd_sel || vmm_pd_sel == Vcpu::invalid())
return;
return ret;
/* allocate vCPU object */
Vcpu &vcpu = *new (_heap) Vcpu(_constrained_md_ram_alloc,
@@ -191,7 +192,7 @@ void Vm_session_component::_create_vcpu(Thread_capability cap)
/* we ran out of caps in core */
if (!vcpu.ds_cap().valid())
return;
return ret;
/* core PD selector */
addr_t const core_pd = platform_specific().core_pd_sel();
@@ -204,7 +205,7 @@ void Vm_session_component::_create_vcpu(Thread_capability cap)
if (res != Nova::NOVA_OK) {
error("create_sm = ", res);
destroy(_heap, &vcpu);
return;
return ret;
}
addr_t const event_base = (1U << Nova::NUM_INITIAL_VCPU_PT_LOG2) * _id_alloc;
@@ -217,7 +218,7 @@ void Vm_session_component::_create_vcpu(Thread_capability cap)
if (res != Nova::NOVA_OK) {
error("create_ec = ", res);
destroy(_heap, &vcpu);
return;
return ret;
}
addr_t const dst_sm_ec_sel = Nova::NUM_INITIAL_PT_RESERVED
@@ -239,11 +240,12 @@ void Vm_session_component::_create_vcpu(Thread_capability cap)
{
error("map sm ", res, " ", _id_alloc);
destroy(_heap, &vcpu);
return;
return ret;
}
_id_alloc++;
_vcpus.insert(&vcpu);
_id_alloc++;
return vcpu.id();
}
void Vm_session_component::_run(Vcpu_id const vcpu_id)

View File

@@ -29,7 +29,6 @@ using namespace Genode;
struct Vcpu;
static Genode::Registry<Genode::Registered<Vcpu> > vcpus;
static unsigned vcpu_id = 0;
struct Vcpu {
@@ -425,8 +424,9 @@ struct Vcpu {
public:
Vcpu(Vm_handler_base &o, unsigned id, Allocator &alloc)
: _obj(o), _alloc(alloc), _id({id}) { }
Vcpu(Vm_handler_base &o, Vm_session::Vcpu_id const id,
Allocator &alloc)
: _obj(o), _alloc(alloc), _id(id) { }
virtual ~Vcpu() { }
@@ -703,9 +703,10 @@ Vm_session_client::create_vcpu(Allocator &alloc, Env &env,
Vm_handler_base &handler)
{
Thread * ep = reinterpret_cast<Thread *>(&handler._rpc_ep);
call<Rpc_create_vcpu>(ep->cap());
Vcpu * vcpu = new (alloc) Registered<Vcpu> (vcpus, handler, vcpu_id++, alloc);
Vcpu * vcpu = new (alloc) Registered<Vcpu> (vcpus, handler,
call<Rpc_create_vcpu>(ep->cap()),
alloc);
vcpu->assign_ds_state(env.rm(), call<Rpc_cpu_state>(vcpu->id()));
Signal_context_capability dontcare_exit;