genode/repos/base-sel4/src/core/include/cnode.h
Norman Feske 9e6f3be806 sel4: update to version 2.1
This patch updates seL4 from the experimental branch of one year ago to
the master branch of version 2.1. The transition has the following
implications.

In contrast to the experimental branch, the master branch has no way to
manually define the allocation of kernel objects within untyped memory
ranges. Instead, the kernel maintains a built-in allocation policy. This
policy rules out the deallocation of once-used parts of untyped memory.
The only way to reuse memory is to revoke the entire untyped memory
range. Consequently, we cannot share a large untyped memory range for
kernel objects of different protection domains. In order to reuse memory
at a reasonably fine granularity, we need to split the initial untyped
memory ranges into small chunks that can be individually revoked. Those
chunks are called "untyped pages". An untyped page is a 4 KiB untyped
memory region.

The bootstrapping of core has to employ a two-stage allocation approach
now. For creating the initial kernel objects for core, which remain
static during the entire lifetime of the system, kernel objects are
created directly out of the initial untyped memory regions as reported
by the kernel. The so-called "initial untyped pool" keeps track of the
consumption of those untyped memory ranges by mimicking the kernel's
internal allocation policy. Kernel objects created this way can be of
any size. For example the phys CNode, which is used to store page-frame
capabilities is 16 MiB in size. Also, core's CSpace uses a relatively
large CNode.

After the initial setup phase, all remaining untyped memory is turned
into untyped pages. From this point on, new created kernel objects
cannot exceed 4 KiB in size because one kernel object cannot span
multiple untyped memory regions. The capability selectors for untyped
pages are organized similarly to those of page-frame capabilities. There
is a new 2nd-level CNode (UNTYPED_CORE_CNODE) that is dimensioned
according to the maximum amount of physical memory (1M entries, each
entry representing 4 KiB). The CNode is organized such that an index
into the CNode directly corresponds to the physical frame number of the
underlying memory. This way, we can easily determine a untyped page
selector for any physical addresses, i.e., for revoking the kernel
objects allocated at a specific physical page. The downside is the need
for another 16 MiB chunk of meta data. Also, we need to keep in mind
that this approach won't scale to 64-bit systems. We will eventually
need to replace the PHYS_CORE_CNODE and UNTYPED_CORE_CNODE by CNode
hierarchies to model a sparsely populated CNode.

The size constrain of kernel objects has the immediate implication that
the VM CSpaces of protection domains must be organized via several
levels of CNodes. I.e., as the top-level CNode of core has a size of
2^12, the remaining 20 PD-specific CSpace address bits are organized as
a 2nd-level 2^4 padding CNode, a 3rd-level 2^8 CNode, and several
4th-level 2^8 leaf CNodes. The latter contain the actual selectors for
the page tables and page-table entries of the respective PD.

As another slight difference from the experimental branch, the master
branch requires the explicit assignment of page directories to an ASID
pool.

Besides the adjustment to the new seL4 version, the patch introduces a
dedicated type for capability selectors. Previously, we just used to
represent them as unsigned integer values, which became increasingly
confusing. The new type 'Cap_sel' is a PD-local capability selector. The
type 'Cnode_index' is an index into a CNode (which is not generally not
the entire CSpace of the PD).

Fixes #1887
2016-02-26 11:36:55 +01:00

171 lines
4.4 KiB
C++

/*
* \brief Utilities for manipulating seL4 CNodes
* \author Norman Feske
* \date 2015-05-04
*/
/*
* Copyright (C) 2015 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _CORE__INCLUDE__CNODE_H_
#define _CORE__INCLUDE__CNODE_H_
/* Genode includes */
#include <util/noncopyable.h>
#include <base/exception.h>
#include <base/allocator.h>
/* core includes */
#include <kernel_object.h>
namespace Genode {
class Cnode_base;
class Cnode;
}
class Genode::Cnode_base
{
private:
Cap_sel const _sel;
size_t const _size_log2;
public:
typedef Cnode_index Index;
Cap_sel sel() const { return _sel; }
size_t size_log2() const { return _size_log2; }
/**
* Copy selector from another CNode
*/
void copy(Cnode_base const &from, Index from_idx, Index to_idx)
{
seL4_CNode const service = sel().value();
seL4_Word const dest_index = to_idx.value();
uint8_t const dest_depth = size_log2();
seL4_CNode const src_root = from.sel().value();
seL4_Word const src_index = from_idx.value();
uint8_t const src_depth = from.size_log2();
seL4_CapRights const rights = seL4_AllRights;
int const ret = seL4_CNode_Copy(service, dest_index, dest_depth,
src_root, src_index, src_depth, rights);
if (ret != 0) {
PWRN("%s: seL4_CNode_Copy (0x%lx) returned %d", __FUNCTION__,
from_idx.value(), ret);
}
}
void copy(Cnode_base const &from, Index idx) { copy(from, idx, idx); }
/**
* Delete selector from CNode
*/
void remove(Index idx)
{
seL4_CNode_Delete(sel().value(), idx.value(), size_log2());
}
/**
* Move selector from another CNode
*/
void move(Cnode_base const &from, Index from_idx, Index to_idx)
{
seL4_CNode const service = sel().value();
seL4_Word const dest_index = to_idx.value();
uint8_t const dest_depth = size_log2();
seL4_CNode const src_root = from.sel().value();
seL4_Word const src_index = from_idx.value();
uint8_t const src_depth = from.size_log2();
int const ret = seL4_CNode_Move(service, dest_index, dest_depth,
src_root, src_index, src_depth);
if (ret != 0) {
PWRN("%s: seL4_CNode_Move (0x%lx) returned %d", __FUNCTION__,
from_idx.value(), ret);
}
}
void move(Cnode_base const &from, Index idx) { move(from, idx, idx); }
/**
* Constructor
*/
Cnode_base(Cap_sel sel, size_t size_log2)
: _sel(sel), _size_log2(size_log2) { }
};
class Genode::Cnode : public Cnode_base, Noncopyable
{
public:
class Untyped_lookup_failed : Exception { };
class Retype_untyped_failed : Exception { };
/**
* Constructor
*
* \param parent_sel CNode where to place the cap selector of the
* new CNode
* \param dst_idx designated index within 'parent_sel' referring to
* the created CNode
* \param size_log2 number of entries in CNode
* \param phys_alloc physical-memory allocator used for allocating
* the CNode backing store
*
* \throw Phys_alloc_failed
* \throw Untyped_address::Lookup_failed
*
* \deprecated
*/
Cnode(Cap_sel parent_sel, Index dst_idx, size_t size_log2,
Range_allocator &phys_alloc)
:
Cnode_base(dst_idx, size_log2)
{
create<Cnode_kobj>(phys_alloc, parent_sel, dst_idx, size_log2);
}
/**
* Constructor
*
* \param parent_sel CNode where to place the cap selector of the
* new CNode
* \param dst_idx designated index within 'parent_sel' referring to
* the created CNode
* \param size_log2 number of entries in CNode
* \param untyped_pool initial untyped memory pool used for allocating
* the CNode backing store
*
* \throw Retype_untyped_failed
* \throw Initial_untyped_pool::Initial_untyped_pool_exhausted
*/
Cnode(Cap_sel parent_sel, Index dst_idx, size_t size_log2,
Initial_untyped_pool &untyped_pool)
:
Cnode_base(dst_idx, size_log2)
{
create<Cnode_kobj>(untyped_pool, parent_sel, dst_idx, size_log2);
}
~Cnode()
{
/* convert CNode back to untyped memory */
/* revert phys allocation */
PDBG("not implemented");
}
};
#endif /* _CORE__INCLUDE__CNODE_H_ */