2015-02-19 14:50:27 +01:00
|
|
|
/*
|
|
|
|
* \brief VM session component for 'base-hw'
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2015-02-17
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2015-2017 Genode Labs GmbH
|
2015-02-19 14:50:27 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2015-02-19 14:50:27 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <util/construct_at.h>
|
|
|
|
|
|
|
|
/* core includes */
|
|
|
|
#include <kernel/core_interface.h>
|
2019-07-15 13:11:28 +02:00
|
|
|
#include <spec/arm/virtualization/vm_session_component.h>
|
2015-02-19 14:50:27 +01:00
|
|
|
#include <platform.h>
|
|
|
|
#include <core_env.h>
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
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 22:00:01 +01:00
|
|
|
static Core_mem_allocator & cma() {
|
|
|
|
return static_cast<Core_mem_allocator&>(platform().core_mem_alloc()); }
|
2017-02-21 13:46:59 +01:00
|
|
|
|
2015-02-19 14:50:27 +01:00
|
|
|
|
2018-09-26 15:53:18 +02:00
|
|
|
void Vm_session_component::_exception_handler(Signal_context_capability handler, Vcpu_id)
|
2015-02-19 14:50:27 +01:00
|
|
|
{
|
2019-10-16 15:07:11 +02:00
|
|
|
if (!_kobj.create(_ds_addr, Capability_space::capid(handler),
|
|
|
|
cma().phys_addr(&_table)))
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::warning("Cannot instantiate vm kernel object, invalid signal context?");
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Vm_session_component::_attach(addr_t phys_addr, addr_t vm_addr, size_t size)
|
|
|
|
{
|
2017-02-21 13:46:59 +01:00
|
|
|
using namespace Hw;
|
|
|
|
|
2016-11-07 18:00:24 +01:00
|
|
|
Page_flags pflags { RW, NO_EXEC, USER, NO_GLOBAL, RAM, CACHED };
|
2015-02-19 14:50:27 +01:00
|
|
|
|
|
|
|
try {
|
2017-02-21 13:46:59 +01:00
|
|
|
_table.insert_translation(vm_addr, phys_addr, size, pflags,
|
|
|
|
_table_array.alloc());
|
2015-06-16 10:59:26 +02:00
|
|
|
return;
|
2017-02-21 13:46:59 +01:00
|
|
|
} catch(Hw::Out_of_tables &) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("Translation table needs to much RAM");
|
2015-02-19 14:50:27 +01:00
|
|
|
} catch(...) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("Invalid mapping ", Genode::Hex(phys_addr), " -> ",
|
|
|
|
Genode::Hex(vm_addr), " (", size, ")");
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-02 17:41:30 +02:00
|
|
|
void Vm_session_component::_attach_vm_memory(Dataspace_component &dsc,
|
|
|
|
addr_t const vm_addr,
|
2018-11-14 14:57:45 +01:00
|
|
|
Attach_attr const attribute)
|
2015-02-19 14:50:27 +01:00
|
|
|
{
|
2018-11-14 14:57:45 +01:00
|
|
|
_attach(dsc.phys_addr() + attribute.offset, vm_addr, attribute.size);
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Vm_session_component::attach_pic(addr_t vm_addr)
|
|
|
|
{
|
2019-03-22 14:23:07 +01:00
|
|
|
_attach(Board::Cpu_mmio::IRQ_CONTROLLER_VT_CPU_BASE, vm_addr,
|
|
|
|
Board::Cpu_mmio::IRQ_CONTROLLER_VT_CPU_SIZE);
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-02 17:41:30 +02:00
|
|
|
void Vm_session_component::_detach_vm_memory(addr_t vm_addr, size_t size)
|
|
|
|
{
|
|
|
|
_table.remove_translation(vm_addr, size, _table_array.alloc());
|
|
|
|
}
|
2015-02-19 14:50:27 +01:00
|
|
|
|
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
void * Vm_session_component::_alloc_table()
|
|
|
|
{
|
|
|
|
void * table;
|
2015-02-19 14:50:27 +01:00
|
|
|
/* get some aligned space for the translation table */
|
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 22:00:01 +01:00
|
|
|
if (!cma().alloc_aligned(sizeof(Table), (void**)&table,
|
|
|
|
Table::ALIGNM_LOG2).ok()) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
error("failed to allocate kernel object");
|
2017-05-08 14:32:03 +02:00
|
|
|
throw Insufficient_ram_quota();
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|
2017-02-21 13:46:59 +01:00
|
|
|
return table;
|
|
|
|
}
|
2015-02-19 14:50:27 +01:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
|
2018-09-26 15:53:18 +02:00
|
|
|
Vm_session_component::Vm_session_component(Rpc_entrypoint &ds_ep,
|
|
|
|
Resources resources,
|
|
|
|
Label const &,
|
|
|
|
Diag,
|
|
|
|
Ram_allocator &ram_alloc,
|
2019-01-11 15:41:29 +01:00
|
|
|
Region_map ®ion_map,
|
2019-04-17 14:16:27 +02:00
|
|
|
unsigned,
|
|
|
|
Trace::Source_registry &)
|
2019-10-16 15:07:11 +02:00
|
|
|
: Ram_quota_guard(resources.ram_quota),
|
|
|
|
Cap_quota_guard(resources.cap_quota),
|
|
|
|
_ep(ds_ep),
|
|
|
|
_constrained_md_ram_alloc(ram_alloc, _ram_quota_guard(), _cap_quota_guard()),
|
|
|
|
_sliced_heap(_constrained_md_ram_alloc, region_map),
|
|
|
|
_region_map(region_map),
|
|
|
|
_table(*construct_at<Table>(_alloc_table())),
|
|
|
|
_table_array(*(new (cma()) Array([this] (void * virt) {
|
|
|
|
return (addr_t)cma().phys_addr(virt);})))
|
2017-02-21 13:46:59 +01:00
|
|
|
{
|
2018-09-26 15:53:18 +02:00
|
|
|
_ds_cap = _constrained_md_ram_alloc.alloc(_ds_size(), Genode::Cache_attribute::UNCACHED);
|
|
|
|
|
|
|
|
try {
|
|
|
|
_ds_addr = region_map.attach(_ds_cap);
|
|
|
|
} catch (...) {
|
|
|
|
_constrained_md_ram_alloc.free(_ds_cap);
|
|
|
|
throw;
|
|
|
|
}
|
2019-04-02 17:41:30 +02:00
|
|
|
|
|
|
|
/* configure managed VM area */
|
|
|
|
_map.add_range(0, 0UL - 0x1000);
|
|
|
|
_map.add_range(0UL - 0x1000, 0x1000);
|
2015-06-16 10:59:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Vm_session_component::~Vm_session_component()
|
|
|
|
{
|
2019-04-02 17:41:30 +02:00
|
|
|
/* detach all regions */
|
|
|
|
while (true) {
|
|
|
|
addr_t out_addr = 0;
|
|
|
|
|
|
|
|
if (!_map.any_block_addr(&out_addr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
detach(out_addr);
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:59:26 +02:00
|
|
|
/* free region in allocator */
|
2018-09-26 15:53:18 +02:00
|
|
|
if (_ds_cap.valid()) {
|
|
|
|
_region_map.detach(_ds_addr);
|
|
|
|
_constrained_md_ram_alloc.free(_ds_cap);
|
|
|
|
}
|
2015-06-16 10:59:26 +02:00
|
|
|
|
|
|
|
/* free guest-to-host page tables */
|
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 22:00:01 +01:00
|
|
|
destroy(platform().core_mem_alloc(), &_table);
|
|
|
|
destroy(platform().core_mem_alloc(), &_table_array);
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|