2013-08-20 19:24:52 +00:00
|
|
|
/*
|
|
|
|
* \brief Utilities for implementing VMMs on Genode/NOVA
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-08-20 19:24:52 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-08-20 19:24:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__VMM__VCPU_THREAD_H_
|
|
|
|
#define _INCLUDE__VMM__VCPU_THREAD_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/thread.h>
|
2013-11-14 10:58:28 +00:00
|
|
|
#include <cpu_session/connection.h>
|
|
|
|
#include <pd_session/connection.h>
|
2016-04-15 13:19:22 +00:00
|
|
|
#include <region_map/client.h>
|
2016-05-10 16:05:38 +00:00
|
|
|
#include <cpu_thread/client.h>
|
2017-02-27 18:54:03 +00:00
|
|
|
#include <nova_native_cpu/client.h>
|
2013-08-20 19:24:52 +00:00
|
|
|
|
2016-03-11 16:32:43 +00:00
|
|
|
/* NOVA includes */
|
|
|
|
#include <nova/native_thread.h>
|
2016-06-15 13:04:54 +00:00
|
|
|
#include <nova/cap_map.h>
|
2016-03-11 16:32:43 +00:00
|
|
|
|
2013-08-20 19:24:52 +00:00
|
|
|
namespace Vmm {
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
class Vcpu_thread;
|
2013-11-14 10:58:28 +00:00
|
|
|
class Vcpu_other_pd;
|
|
|
|
class Vcpu_same_pd;
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 10:58:28 +00:00
|
|
|
class Vmm::Vcpu_thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual Genode::addr_t exc_base() = 0;
|
|
|
|
virtual void start(Genode::addr_t) = 0;
|
2018-03-10 12:52:23 +00:00
|
|
|
|
|
|
|
virtual ~Vcpu_thread() { };
|
2013-11-14 10:58:28 +00:00
|
|
|
};
|
2013-08-20 19:24:52 +00:00
|
|
|
|
2013-11-14 10:58:28 +00:00
|
|
|
class Vmm::Vcpu_other_pd : public Vmm::Vcpu_thread
|
2013-08-20 19:24:52 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2016-11-24 20:57:33 +00:00
|
|
|
Genode::Capability<Genode::Pd_session> _pd_cap;
|
2014-07-16 19:43:41 +00:00
|
|
|
Genode::Affinity::Location _location;
|
|
|
|
Genode::Cpu_session *_cpu_session;
|
2013-11-14 10:58:28 +00:00
|
|
|
|
|
|
|
Genode::addr_t _exc_pt_sel;
|
|
|
|
|
2018-03-10 12:52:23 +00:00
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Vcpu_other_pd(Vcpu_other_pd const &);
|
|
|
|
Vcpu_other_pd &operator = (Vcpu_other_pd const &);
|
|
|
|
|
2013-11-14 10:58:28 +00:00
|
|
|
public:
|
|
|
|
|
2014-07-16 19:43:41 +00:00
|
|
|
Vcpu_other_pd(Cpu_session * cpu_session,
|
2016-11-15 22:10:30 +00:00
|
|
|
Genode::Affinity::Location location,
|
2016-11-24 20:57:33 +00:00
|
|
|
Genode::Capability<Genode::Pd_session> pd_cap,
|
2016-11-15 22:10:30 +00:00
|
|
|
Genode::size_t = 0 /* stack_size */)
|
2013-11-14 10:58:28 +00:00
|
|
|
:
|
2016-11-24 20:57:33 +00:00
|
|
|
_pd_cap(pd_cap), _location(location), _cpu_session(cpu_session),
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 21:00:01 +00:00
|
|
|
_exc_pt_sel(Genode::cap_map().insert(Nova::NUM_INITIAL_VCPU_PT_LOG2))
|
2013-11-14 10:58:28 +00:00
|
|
|
{ }
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void start(Genode::addr_t sel_ec) override
|
2013-11-14 10:58:28 +00:00
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
2015-03-27 13:05:55 +00:00
|
|
|
Thread_capability vcpu_vm =
|
2016-11-24 20:57:33 +00:00
|
|
|
_cpu_session->create_thread(_pd_cap, "vCPU",
|
2016-05-04 10:27:17 +00:00
|
|
|
_location, Cpu_session::Weight());
|
2013-11-14 10:58:28 +00:00
|
|
|
|
|
|
|
/* tell parent that this will be a vCPU */
|
2017-02-27 18:54:03 +00:00
|
|
|
Nova_native_cpu::Thread_type thread_type { Nova_native_cpu::Thread_type::VCPU };
|
|
|
|
Nova_native_cpu::Exception_base exception_base { _exc_pt_sel };
|
|
|
|
Nova_native_cpu_client native_cpu(_cpu_session->native_cpu());
|
|
|
|
native_cpu.thread_type(vcpu_vm, thread_type, exception_base);
|
2013-08-20 19:24:52 +00:00
|
|
|
|
2016-05-10 16:05:38 +00:00
|
|
|
Cpu_thread_client cpu_thread(vcpu_vm);
|
2013-11-14 10:58:28 +00:00
|
|
|
|
|
|
|
/*
|
2016-11-30 18:36:32 +00:00
|
|
|
* Translate vcpu_vm thread cap via current executing thread,
|
|
|
|
* which is used to lookup current PD to delegate VM-exit portals.
|
2013-11-14 10:58:28 +00:00
|
|
|
*/
|
2016-11-30 18:36:32 +00:00
|
|
|
addr_t const current = Thread::myself()->native_thread().exc_pt_sel
|
|
|
|
+ Nova::PT_SEL_PAGE_FAULT;
|
|
|
|
translate_remote_pager(current, vcpu_vm.local_name());
|
2013-11-14 10:58:28 +00:00
|
|
|
|
|
|
|
/* start vCPU in separate PD */
|
2016-05-10 16:05:38 +00:00
|
|
|
cpu_thread.start(0, 0);
|
2013-11-14 10:58:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Request native EC thread cap and put it next to the
|
|
|
|
* SM cap - see Vcpu_dispatcher->sel_sm_ec description
|
|
|
|
*/
|
2016-11-30 18:36:32 +00:00
|
|
|
addr_t const pager_pt = _exc_pt_sel + Nova::PT_SEL_PAGE_FAULT;
|
|
|
|
request_native_ec_cap(pager_pt, sel_ec);
|
|
|
|
|
|
|
|
/* solely needed for vcpu to request native ec cap - drop it */
|
|
|
|
Nova::revoke(Nova::Obj_crd(pager_pt, 0));
|
2016-11-24 20:57:33 +00:00
|
|
|
|
|
|
|
/* request creation of SC to let vCPU run */
|
|
|
|
cpu_thread.resume();
|
2013-11-14 10:58:28 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
Genode::addr_t exc_base() override { return _exc_pt_sel; }
|
2013-11-14 10:58:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-04 10:27:17 +00:00
|
|
|
class Vmm::Vcpu_same_pd : public Vmm::Vcpu_thread, Genode::Thread
|
2013-11-14 10:58:28 +00:00
|
|
|
{
|
2016-05-04 10:27:17 +00:00
|
|
|
enum { WEIGHT = Genode::Cpu_session::Weight::DEFAULT_WEIGHT };
|
2015-03-27 13:05:55 +00:00
|
|
|
|
2013-08-20 19:24:52 +00:00
|
|
|
public:
|
|
|
|
|
2016-11-15 22:10:30 +00:00
|
|
|
Vcpu_same_pd(Cpu_session * cpu_session,
|
|
|
|
Genode::Affinity::Location location,
|
2016-11-24 20:57:33 +00:00
|
|
|
Genode::Capability<Genode::Pd_session>,
|
2016-11-15 22:10:30 +00:00
|
|
|
Genode::size_t stack_size)
|
2013-08-20 19:24:52 +00:00
|
|
|
:
|
2016-05-04 10:27:17 +00:00
|
|
|
Thread(WEIGHT, "vCPU", stack_size, Type::NORMAL, cpu_session, location)
|
2013-08-20 19:24:52 +00:00
|
|
|
{
|
|
|
|
/* release pre-allocated selectors of Thread */
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 21:00:01 +00:00
|
|
|
Genode::cap_map().remove(native_thread().exc_pt_sel, Nova::NUM_INITIAL_PT_LOG2);
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
/* allocate correct number of selectors */
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 21:00:01 +00:00
|
|
|
this->native_thread().exc_pt_sel = cap_map().insert(Nova::NUM_INITIAL_VCPU_PT_LOG2);
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
/* tell generic thread code that this becomes a vCPU */
|
2016-05-11 16:21:47 +00:00
|
|
|
this->native_thread().vcpu = true;
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 10:58:28 +00:00
|
|
|
~Vcpu_same_pd()
|
2013-08-20 19:24:52 +00:00
|
|
|
{
|
|
|
|
using namespace Nova;
|
|
|
|
|
2016-03-11 16:32:43 +00:00
|
|
|
revoke(Nova::Obj_crd(this->native_thread().exc_pt_sel, NUM_INITIAL_VCPU_PT_LOG2));
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 21:00:01 +00:00
|
|
|
cap_map().remove(this->native_thread().exc_pt_sel, NUM_INITIAL_VCPU_PT_LOG2, false);
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
/* allocate selectors for ~Thread */
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 21:00:01 +00:00
|
|
|
this->native_thread().exc_pt_sel = cap_map().insert(Nova::NUM_INITIAL_PT_LOG2);
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
addr_t exc_base() override { return this->native_thread().exc_pt_sel; }
|
2013-08-20 19:24:52 +00:00
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void start(Genode::addr_t sel_ec) override
|
2013-08-20 19:24:52 +00:00
|
|
|
{
|
2016-05-04 10:27:17 +00:00
|
|
|
this->Thread::start();
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Request native EC thread cap and put it next to the
|
|
|
|
* SM cap - see Vcpu_dispatcher->sel_sm_ec description
|
|
|
|
*/
|
2016-11-30 18:36:32 +00:00
|
|
|
addr_t const pager_pt = exc_base() + Nova::PT_SEL_PAGE_FAULT;
|
|
|
|
request_native_ec_cap(pager_pt, sel_ec);
|
|
|
|
|
|
|
|
/* solely needed for vcpu to request native ec cap - drop it */
|
|
|
|
Nova::revoke(Nova::Obj_crd(pager_pt, 0));
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void entry() override { }
|
2013-08-20 19:24:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__VMM__VCPU_THREAD_H_ */
|