base-hw: Core PD as Main member

Let the Core protection-domain object be a member of the one Kernel::Main
object instead of having it as global static variable.

Ref #4217
This commit is contained in:
Martin Stein 2021-07-16 16:35:54 +02:00 committed by Norman Feske
parent d6e347163d
commit b6641eaa25
24 changed files with 132 additions and 126 deletions

View File

@ -51,7 +51,6 @@ SRC_CC += pager.cc
SRC_CC += _main.cc
SRC_CC += kernel/cpu.cc
SRC_CC += kernel/cpu_scheduler.cc
SRC_CC += kernel/init.cc
SRC_CC += kernel/ipc_node.cc
SRC_CC += kernel/irq.cc
SRC_CC += kernel/main.cc

View File

@ -14,7 +14,6 @@
/* core includes */
#include <kernel/cpu.h>
#include <kernel/kernel.h>
#include <kernel/thread.h>
#include <kernel/irq.h>
#include <kernel/pd.h>
@ -106,14 +105,15 @@ extern "C" void idle_thread_main(void);
Cpu::Idle_thread::Idle_thread(Irq::Pool &user_irq_pool,
Cpu_pool &cpu_pool,
Cpu &cpu)
Cpu &cpu,
Pd &core_pd)
:
Thread { user_irq_pool, cpu_pool, "idle" }
Thread { user_irq_pool, cpu_pool, core_pd, "idle" }
{
regs->ip = (addr_t)&idle_thread_main;
affinity(cpu);
Thread::_pd = &core_pd();
Thread::_pd = &core_pd;
}
@ -175,12 +175,13 @@ addr_t Cpu::stack_start()
Cpu::Cpu(unsigned const id,
Irq::Pool &user_irq_pool,
Cpu_pool &cpu_pool)
Cpu_pool &cpu_pool,
Pd &core_pd)
:
_id { id },
_timer { *this },
_scheduler { _idle, _quota(), _fill() },
_idle { user_irq_pool, cpu_pool, *this },
_idle { user_irq_pool, cpu_pool, *this, core_pd },
_ipi_irq { *this },
_global_work_list { cpu_pool.work_list() }
{
@ -192,10 +193,11 @@ Cpu::Cpu(unsigned const id,
** Cpu_pool **
**************/
void Cpu_pool::initialize_executing_cpu(Irq::Pool &user_irq_pool)
void Cpu_pool::initialize_executing_cpu(Irq::Pool &user_irq_pool,
Pd &core_pd)
{
unsigned id = Cpu::executing_id();
_cpus[id].construct(id, user_irq_pool, *this);
_cpus[id].construct(id, user_irq_pool, *this, core_pd);
}

View File

@ -104,7 +104,8 @@ class Kernel::Cpu : public Genode::Cpu, private Irq::Pool, private Timeout
*/
Idle_thread(Irq::Pool &user_irq_pool,
Cpu_pool &cpu_pool,
Cpu &cpu);
Cpu &cpu,
Pd &core_pd);
};
@ -131,7 +132,8 @@ class Kernel::Cpu : public Genode::Cpu, private Irq::Pool, private Timeout
*/
Cpu(unsigned const id,
Irq::Pool &user_irq_pool,
Cpu_pool &cpu_pool);
Cpu_pool &cpu_pool,
Pd &core_pd);
static inline unsigned primary_id() { return 0; }
@ -202,7 +204,8 @@ class Kernel::Cpu_pool
Cpu_pool(unsigned nr_of_cpus);
void initialize_executing_cpu(Irq::Pool &user_irq_pool);
void initialize_executing_cpu(Irq::Pool &user_irq_pool,
Pd &core_pd);
/**
* Return object of CPU 'id'

View File

@ -1,30 +0,0 @@
/*
* \brief Common kernel initialization
* \author Martin Stein
* \author Stefan Kalkowski
* \date 2015-12-20
*/
/*
* 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.
*/
/* core includes */
#include <kernel/pd.h>
#include <platform_pd.h>
/* base includes */
#include <base/internal/unmanaged_singleton.h>
using namespace Kernel;
static_assert(sizeof(Genode::sizet_arithm_t) >= 2 * sizeof(size_t),
"Bad result type for size_t arithmetics.");
Pd &Kernel::core_pd() {
return unmanaged_singleton<Genode::Core_platform_pd>()->kernel_pd(); }

View File

@ -20,7 +20,6 @@
/* core includes */
#include <kernel/ipc_node.h>
#include <kernel/kernel.h>
#include <kernel/thread.h>
using namespace Kernel;

View File

@ -12,7 +12,6 @@
*/
/* core includes */
#include <kernel/kernel.h>
#include <kernel/cpu.h>
#include <kernel/irq.h>

View File

@ -1,25 +0,0 @@
/*
* \brief Singlethreaded minimalistic kernel
* \author Martin Stein
* \author Stefan Kalkowski
* \date 2013-09-30
*/
/*
* Copyright (C) 2013-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 _CORE__KERNEL__KERNEL_H_
#define _CORE__KERNEL__KERNEL_H_
namespace Kernel {
class Pd;
Pd &core_pd();
}
#endif /* _CORE__KERNEL__KERNEL_H_ */

View File

@ -15,10 +15,15 @@
/* base includes */
#include <util/reconstructible.h>
/* base Core includes */
#include <map_local.h>
/* base-hw Core includes */
#include <kernel/cpu.h>
#include <kernel/lock.h>
#include <kernel/main.h>
#include <platform_pd.h>
#include <platform_thread.h>
/* base-hw-internal includes */
#include <hw/boot_info.h>
@ -43,11 +48,16 @@ class Kernel::Main
Lock _data_lock { };
Cpu_pool _cpu_pool;
Irq::Pool _user_irq_pool { };
Genode::Core_platform_pd _core_platform_pd { };
Genode::Constructible<Core_main_thread> _core_main_thread { };
void _handle_kernel_entry();
Main(unsigned nr_of_cpus);
public:
static Genode::Platform_pd &core_platform_pd();
};
@ -83,6 +93,9 @@ void Kernel::main_handle_kernel_entry()
void Kernel::main_initialize_and_handle_kernel_entry()
{
static_assert(sizeof(Genode::sizet_arithm_t) >= 2 * sizeof(size_t),
"Bad result type for size_t arithmetics.");
using Boot_info = Hw::Boot_info<Board::Boot_info>;
static volatile bool instance_initialized { false };
@ -121,7 +134,8 @@ void Kernel::main_initialize_and_handle_kernel_entry()
Lock::Guard guard(Main::_instance->_data_lock);
instance_initialized = true;
Main::_instance->_cpu_pool.initialize_executing_cpu(
Main::_instance->_user_irq_pool);
Main::_instance->_user_irq_pool,
Main::_instance->_core_platform_pd.kernel_pd());
nr_of_initialized_cpus++;
};
@ -148,7 +162,8 @@ void Kernel::main_initialize_and_handle_kernel_entry()
Main::_instance->_core_main_thread.construct(
Main::_instance->_user_irq_pool,
Main::_instance->_cpu_pool);
Main::_instance->_cpu_pool,
Main::_instance->_core_platform_pd.kernel_pd());
boot_info.core_main_thread_utcb =
(addr_t)Main::_instance->_core_main_thread->utcb();
@ -170,7 +185,38 @@ void Kernel::main_initialize_and_handle_kernel_entry()
}
Genode::Platform_pd &Kernel::Main::core_platform_pd()
{
return _instance->_core_platform_pd;
}
Kernel::time_t Kernel::main_read_idle_thread_execution_time(unsigned cpu_idx)
{
return Main::_instance->_cpu_pool.cpu(cpu_idx).idle_thread().execution_time();
}
Genode::Platform_pd &
Genode::Platform_thread::_kernel_main_get_core_platform_pd()
{
return Kernel::Main::core_platform_pd();
}
bool Genode::map_local(addr_t from_phys, addr_t to_virt, size_t num_pages,
Page_flags flags)
{
return
Kernel::Main::core_platform_pd().insert_translation(
to_virt, from_phys, num_pages * get_page_size(), flags);
}
bool Genode::unmap_local(addr_t virt_addr, size_t num_pages)
{
Kernel::Main::core_platform_pd().flush(
virt_addr, num_pages * get_page_size());
return true;
}

View File

@ -1,6 +1,5 @@
#include <kernel/object.h>
#include <kernel/pd.h>
#include <kernel/kernel.h>
#include <util/construct_at.h>

View File

@ -23,7 +23,6 @@
/* core includes */
#include <kernel/core_interface.h>
#include <kernel/interface.h>
#include <kernel/kernel.h>
namespace Kernel {
@ -228,9 +227,24 @@ class Kernel::Core_object_identity : public Object_identity,
{
public:
Core_object_identity(T & object)
: Object_identity(object.kernel_object()),
Object_identity_reference(this, core_pd()) { }
/**
* Constructor used for objects other than the Core PD
*/
Core_object_identity(Pd &core_pd,
T &object)
:
Object_identity(object.kernel_object()),
Object_identity_reference(this, core_pd)
{ }
/**
* Constructor used for Core PD object
*/
Core_object_identity(T &core_pd)
:
Object_identity(core_pd.kernel_object()),
Object_identity_reference(this, core_pd)
{ }
capid_t core_capid() { return capid(); }
@ -248,9 +262,26 @@ class Kernel::Core_object : public T, Kernel::Core_object_identity<T>
{
public:
/**
* Constructor used for objects other than the Core PD
*/
template <typename... ARGS>
Core_object(Pd &core_pd,
ARGS &&... args)
:
T(args...),
Core_object_identity<T>(core_pd, *static_cast<T*>(this))
{ }
/**
* Constructor used for Core PD object
*/
template <typename... ARGS>
Core_object(ARGS &&... args)
: T(args...), Core_object_identity<T>(*static_cast<T*>(this)) { }
:
T(args...),
Core_object_identity<T>(*static_cast<T*>(this))
{ }
using Kernel::Core_object_identity<T>::core_capid;
using Kernel::Core_object_identity<T>::capid;

View File

@ -116,12 +116,4 @@ class Kernel::Pd
bool core_pd() const { return _core_pd; }
};
template<>
inline Kernel::Core_object_identity<Kernel::Pd>::Core_object_identity(Kernel::Pd & pd)
:
Object_identity(pd.kernel_object()),
Object_identity_reference(this, pd.core_pd() ? pd : core_pd())
{ }
#endif /* _CORE__KERNEL__PD_H_ */

View File

@ -24,7 +24,6 @@
/* core includes */
#include <hw/assert.h>
#include <kernel/cpu.h>
#include <kernel/kernel.h>
#include <kernel/thread.h>
#include <kernel/irq.h>
#include <kernel/log.h>
@ -98,7 +97,7 @@ void Thread::ipc_copy_msg(Thread &sender)
Reference *dst_oir = oir->find(pd());
/* if it is not found, and the target is not core, create a reference */
if (!dst_oir && (&pd() != &core_pd())) {
if (!dst_oir && (&pd() != &_core_pd)) {
dst_oir = oir->factory(_obj_id_ref_ptr[i], pd());
if (dst_oir) _obj_id_ref_ptr[i] = nullptr;
}
@ -683,7 +682,7 @@ void Thread::_call_new_obj()
using Thread_identity = Genode::Constructible<Core_object_identity<Thread>>;
Thread_identity & coi = *(Thread_identity*)user_arg_1();
coi.construct(*thread);
coi.construct(_core_pd, *thread);
user_arg_0(coi->core_capid());
}
@ -774,12 +773,13 @@ void Thread::_call()
/* switch over kernel calls that are restricted to core */
switch (call_id) {
case call_id_new_thread():
_call_new<Thread>(_user_irq_pool, _cpu_pool, (unsigned) user_arg_2(),
_call_new<Thread>(_user_irq_pool, _cpu_pool, _core_pd,
(unsigned) user_arg_2(),
(unsigned) _core_to_kernel_quota(user_arg_3()),
(char const *) user_arg_4());
return;
case call_id_new_core_thread():
_call_new<Thread>(_user_irq_pool, _cpu_pool,
_call_new<Thread>(_user_irq_pool, _cpu_pool, _core_pd,
(char const *) user_arg_2());
return;
case call_id_thread_quota(): _call_thread_quota(); return;
@ -839,6 +839,7 @@ void Thread::_mmu_exception()
Thread::Thread(Irq::Pool &user_irq_pool,
Cpu_pool &cpu_pool,
Pd &core_pd,
unsigned const priority,
unsigned const quota,
char const *const label,
@ -848,6 +849,7 @@ Thread::Thread(Irq::Pool &user_irq_pool,
Cpu_job { priority, quota },
_user_irq_pool { user_irq_pool },
_cpu_pool { cpu_pool },
_core_pd { core_pd },
_ipc_node { *this },
_state { AWAITS_START },
_label { label },
@ -874,9 +876,11 @@ Genode::uint8_t __initial_stack_base[DEFAULT_STACK_SIZE];
** Core_main_thread **
**********************/
Core_main_thread::Core_main_thread(Irq::Pool &user_irq_pool, Cpu_pool &cpu_pool)
Core_main_thread::Core_main_thread(Irq::Pool &user_irq_pool,
Cpu_pool &cpu_pool,
Pd &core_pd)
:
Core_object<Thread>(user_irq_pool, cpu_pool, "core")
Core_object<Thread>(core_pd, user_irq_pool, cpu_pool, core_pd, "core")
{
using namespace Genode;
@ -898,6 +902,6 @@ Core_main_thread::Core_main_thread(Irq::Pool &user_irq_pool, Cpu_pool &cpu_pool)
affinity(_cpu_pool.primary_cpu());
_utcb = utcb;
Thread::_pd = &core_pd();
Thread::_pd = &core_pd;
_become_active();
}

View File

@ -133,6 +133,7 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout
Irq::Pool &_user_irq_pool;
Cpu_pool &_cpu_pool;
Pd &_core_pd;
void *_obj_id_ref_ptr[MAX_RCV_CAPS] { nullptr };
Ipc_node _ipc_node;
capid_t _ipc_capid { cap_id_invalid() };
@ -264,7 +265,7 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout
{
Genode::Kernel_object<T> & kobj =
*(Genode::Kernel_object<T>*)user_arg_1();
kobj.construct(args...);
kobj.construct(_core_pd, args...);
user_arg_0(kobj->core_capid());
}
@ -295,6 +296,7 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout
*/
Thread(Irq::Pool &user_irq_pool,
Cpu_pool &cpu_pool,
Pd &core_pd,
unsigned const priority,
unsigned const quota,
char const *const label,
@ -307,9 +309,11 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout
*/
Thread(Irq::Pool &user_irq_pool,
Cpu_pool &cpu_pool,
Pd &core_pd,
char const *const label)
:
Thread(user_irq_pool, cpu_pool, Cpu_priority::min(), 0, label, true)
Thread(user_irq_pool, cpu_pool, core_pd, Cpu_priority::min(), 0,
label, true)
{ }
~Thread();
@ -443,7 +447,9 @@ class Kernel::Core_main_thread : public Core_object<Kernel::Thread>
{
public:
Core_main_thread(Irq::Pool &user_irq_pool, Cpu_pool &cpu_pool);
Core_main_thread(Irq::Pool &user_irq_pool,
Cpu_pool &cpu_pool,
Pd &core_pd);
};
#endif /* _CORE__KERNEL__THREAD_H_ */

View File

@ -18,7 +18,6 @@ namespace Genode { class Vm_state; }
/* core includes */
#include <kernel/cpu_context.h>
#include <kernel/kernel.h>
#include <kernel/pd.h>
#include <kernel/signal_receiver.h>

View File

@ -271,23 +271,6 @@ Platform::Platform()
** Support for core memory management **
****************************************/
bool Genode::map_local(addr_t from_phys, addr_t to_virt, size_t num_pages,
Page_flags flags)
{
Platform_pd &pd = Kernel::core_pd().platform_pd();
return pd.insert_translation(to_virt, from_phys,
num_pages * get_page_size(), flags);
}
bool Genode::unmap_local(addr_t virt_addr, size_t num_pages)
{
Platform_pd &pd = Kernel::core_pd().platform_pd();
pd.flush(virt_addr, num_pages * get_page_size());
return true;
}
bool Mapped_mem_allocator::_map_local(addr_t virt_addr, addr_t phys_addr,
unsigned size) {
return ::map_local(phys_addr, virt_addr, size / get_page_size()); }

View File

@ -88,7 +88,7 @@ class Hw::Address_space : public Genode::Address_space
Kernel_object<Kernel::Pd> _kobj;
/**
* Core-specific constructor
* Constructor used for the Core PD object
*
* \param tt reference to translation table
* \param tt_alloc reference to translation table allocator
@ -101,7 +101,7 @@ class Hw::Address_space : public Genode::Address_space
public:
/**
* Constructor
* Constructor used for objects other than the Core PD
*
* \param pd reference to platform pd object
*/
@ -182,7 +182,7 @@ class Genode::Platform_pd : public Hw::Address_space,
protected:
/**
* Constructor for core pd
* Constructor used for the Core PD object
*
* \param tt translation table address
* \param tt_alloc translation table allocator
@ -193,7 +193,7 @@ class Genode::Platform_pd : public Hw::Address_space,
public:
/**
* Constructor for non-core pd
* Constructor used for objects other than the Core PD
*
* \param label name of protection domain
*/

View File

@ -25,7 +25,7 @@
/* kernel includes */
#include <kernel/pd.h>
#include <kernel/kernel.h>
#include <kernel/main.h>
using namespace Genode;
@ -62,7 +62,7 @@ void Platform_thread::quota(size_t const quota)
Platform_thread::Platform_thread(Label const &label, Native_utcb &utcb)
:
_label(label),
_pd(&Kernel::core_pd().platform_pd()),
_pd(&_kernel_main_get_core_platform_pd()),
_pager(nullptr),
_utcb_core_addr(&utcb),
_utcb_pd_addr(&utcb),

View File

@ -93,6 +93,8 @@ class Genode::Platform_thread : Noncopyable
virt_prio);
}
Platform_pd &_kernel_main_get_core_platform_pd();
public:
/**

View File

@ -24,7 +24,6 @@
/* local includes */
#include <kernel/interface_support.h>
#include <kernel/kernel.h>
#include <board.h>
#include <util.h>

View File

@ -11,8 +11,8 @@
* under the terms of the GNU Affero General Public License version 3.
*/
/* base-hw Core includes */
#include <kernel/cpu.h>
#include <kernel/kernel.h>
void Kernel::panic(Genode::Cpu_state * state) {

View File

@ -12,11 +12,12 @@
* under the terms of the GNU Affero General Public License version 3.
*/
/* base includes */
#include <cpu/memory_barrier.h>
/* base-hw Core includes */
#include <platform_pd.h>
#include <kernel/cpu.h>
#include <kernel/kernel.h>
#include <kernel/pd.h>
#include <kernel/thread.h>

View File

@ -14,7 +14,6 @@
#include <platform_pd.h>
#include <kernel/cpu.h>
#include <kernel/kernel.h>
#include <kernel/pd.h>
#include <kernel/thread.h>

View File

@ -14,7 +14,6 @@
/* core includes */
#include <kernel/cpu.h>
#include <kernel/kernel.h>
void Kernel::Cpu::_arch_init()

View File

@ -23,7 +23,6 @@
/* core includes */
#include <map_local.h>
#include <kernel/kernel.h>
#include <platform.h>
#include <platform_thread.h>
#include <trace/source_registry.h>