2013-08-20 19:24:52 +00:00
|
|
|
/*
|
|
|
|
* \brief Utilities for implementing VMMs on Genode/NOVA
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-20
|
|
|
|
*
|
|
|
|
* The VMM and the guest share the same PD. However, the guest's view on the PD
|
|
|
|
* is restricted to the guest-physical-to-VMM-local mappings installed by the
|
|
|
|
* VMM for the VCPU's EC.
|
|
|
|
*
|
|
|
|
* The guest memory is shadowed at the lower portion of the VMM's address
|
|
|
|
* space. If the guest (the VCPU EC) tries to access a page that has no mapping
|
|
|
|
* in the VMM's PD, NOVA does not generate a page-fault (which would be
|
|
|
|
* delivered to the pager of the VMM, i.e., core) but it produces a NPT
|
|
|
|
* virtualization event handled locally by the VMM. The NPT event handler is
|
|
|
|
* the '_svm_npt' function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
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__GUEST_MEMORY_H_
|
|
|
|
#define _INCLUDE__VMM__GUEST_MEMORY_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
2017-01-03 10:41:42 +00:00
|
|
|
#include <base/attached_ram_dataspace.h>
|
|
|
|
#include <base/env.h>
|
2013-08-20 19:24:52 +00:00
|
|
|
#include <rm_session/connection.h>
|
2016-04-15 13:19:22 +00:00
|
|
|
#include <region_map/client.h>
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
/* VMM utilities includes */
|
|
|
|
#include <vmm/types.h>
|
|
|
|
|
|
|
|
namespace Vmm {
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
class Virtual_reservation;
|
|
|
|
class Guest_memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The 'Virtual_reservation' is a managed dataspace that occupies the lower
|
|
|
|
* part of the address space, which contains the shadow of the VCPU's physical
|
|
|
|
* memory.
|
|
|
|
*/
|
2016-04-15 13:19:22 +00:00
|
|
|
struct Vmm::Virtual_reservation : private Rm_connection, Region_map_client
|
2013-08-20 19:24:52 +00:00
|
|
|
{
|
2017-01-03 10:41:42 +00:00
|
|
|
Genode::Env &_env;
|
|
|
|
|
|
|
|
Virtual_reservation(Genode::Env &env, addr_t vm_size)
|
2013-08-20 19:24:52 +00:00
|
|
|
:
|
2017-01-03 10:41:42 +00:00
|
|
|
Rm_connection(env),
|
|
|
|
Region_map_client(Rm_connection::create(vm_size)),
|
|
|
|
_env(env)
|
2013-08-20 19:24:52 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
/*
|
|
|
|
* Attach reservation to the beginning of the local address
|
|
|
|
* space. We leave out the very first page because core denies
|
|
|
|
* the attachment of anything at the zero page.
|
|
|
|
*/
|
2017-01-03 10:41:42 +00:00
|
|
|
env.rm().attach_at(Region_map_client::dataspace(), PAGE_SIZE, 0,
|
|
|
|
PAGE_SIZE);
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
} catch (Rm_session::Region_conflict) {
|
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 17:07:09 +00:00
|
|
|
error("region conflict while attaching guest-physical memory");
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~Virtual_reservation()
|
|
|
|
{
|
2017-01-03 10:41:42 +00:00
|
|
|
_env.rm().detach((void *)PAGE_SIZE);
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__VMM__GUEST_MEMORY_H_ */
|