gem5
|
KVM VM container. More...
#include <vm.hh>
Classes | |
class | MemorySlot |
Structures tracking memory slots. More... | |
struct | MemSlot |
Public Member Functions | |
KvmVM (KvmVMParams *params) | |
virtual | ~KvmVM () |
void | notifyFork () |
Notify a child process of a fork. More... | |
void | setTSSAddress (Addr tss_address) |
Setup a shared three-page memory region used by the internals of KVM. More... | |
void | createIRQChip () |
Create an in-kernel interrupt controller. More... | |
void | setIRQLine (uint32_t irq, bool high) |
Set the status of an IRQ line using KVM_IRQ_LINE. More... | |
bool | hasKernelIRQChip () const |
Is in-kernel IRQ chip emulation enabled? More... | |
const MemSlot | allocMemSlot (uint64_t size) |
Allocate a memory slot within the VM. More... | |
void | setupMemSlot (const MemSlot slot, void *host_addr, Addr guest_addr, uint32_t flags) |
Setup a region of physical memory in the guest. More... | |
void | disableMemSlot (const MemSlot slot) |
Disable a memory slot. More... | |
void | freeMemSlot (const MemSlot slot) |
Free a previously allocated memory slot. More... | |
int | createDevice (uint32_t type, uint32_t flags=0) |
Create an in-kernel device model. More... | |
void | setSystem (System *s) |
Initialize system pointer. More... | |
long | contextIdToVCpuId (ContextID ctx) const |
Get the VCPUID for a given context. More... | |
void | coalesceMMIO (Addr start, int size) |
Request coalescing MMIO for a memory range. More... | |
void | coalesceMMIO (const AddrRange &range) |
Request coalescing MMIO for a memory range. More... | |
Public Member Functions inherited from SimObject | |
const Params * | params () const |
SimObject (const Params *_params) | |
virtual | ~SimObject () |
virtual const std::string | name () const |
virtual void | init () |
init() is called after all C++ SimObjects have been created and all ports are connected. More... | |
virtual void | loadState (CheckpointIn &cp) |
loadState() is called on each SimObject when restoring from a checkpoint. More... | |
virtual void | initState () |
initState() is called on each SimObject when not restoring from a checkpoint. More... | |
virtual void | regStats () |
Register statistics for this object. More... | |
virtual void | resetStats () |
Reset statistics associated with this object. More... | |
virtual void | regProbePoints () |
Register probe points for this object. More... | |
virtual void | regProbeListeners () |
Register probe listeners for this object. More... | |
ProbeManager * | getProbeManager () |
Get the probe manager for this object. More... | |
virtual void | startup () |
startup() is the final initialization call before simulation. More... | |
DrainState | drain () override |
Provide a default implementation of the drain interface for objects that don't need draining. More... | |
virtual void | memWriteback () |
Write back dirty buffers to memory using functional writes. More... | |
virtual void | memInvalidate () |
Invalidate the contents of memory buffers. More... | |
void | serialize (CheckpointOut &cp) const override |
Serialize an object. More... | |
void | unserialize (CheckpointIn &cp) override |
Unserialize an object. More... | |
Public Member Functions inherited from EventManager | |
EventManager (EventManager &em) | |
EventManager (EventManager *em) | |
EventManager (EventQueue *eq) | |
EventQueue * | eventQueue () const |
void | schedule (Event &event, Tick when) |
void | deschedule (Event &event) |
void | reschedule (Event &event, Tick when, bool always=false) |
void | schedule (Event *event, Tick when) |
void | deschedule (Event *event) |
void | reschedule (Event *event, Tick when, bool always=false) |
void | wakeupEventQueue (Tick when=(Tick)-1) |
void | setCurTick (Tick newVal) |
Public Member Functions inherited from Serializable | |
Serializable () | |
virtual | ~Serializable () |
void | serializeSection (CheckpointOut &cp, const char *name) const |
Serialize an object into a new section. More... | |
void | serializeSection (CheckpointOut &cp, const std::string &name) const |
void | unserializeSection (CheckpointIn &cp, const char *name) |
Unserialize an a child object. More... | |
void | unserializeSection (CheckpointIn &cp, const std::string &name) |
Public Member Functions inherited from Drainable | |
DrainState | drainState () const |
Return the current drain state of an object. More... | |
Public Attributes | |
Kvm * | kvm |
Global KVM interface. More... | |
Protected Member Functions | |
void | cpuStartup () |
VM CPU initialization code. More... | |
void | delayedStartup () |
Delayed initialization, executed once before the first CPU starts. More... | |
int | createVCPU (long vcpuID) |
Create a new vCPU within a VM. More... | |
long | allocVCPUID () |
Allocate a new vCPU ID within the VM. More... | |
int | ioctl (int request, long p1) const |
KVM VM ioctl interface. More... | |
int | ioctl (int request, void *p1) const |
int | ioctl (int request) const |
void | setUserMemoryRegion (uint32_t slot, void *host_addr, Addr guest_addr, uint64_t len, uint32_t flags) |
Setup a region of physical memory in the guest. More... | |
Protected Member Functions inherited from Drainable | |
Drainable () | |
virtual | ~Drainable () |
virtual void | drainResume () |
Resume execution after a successful drain. More... | |
void | signalDrainDone () const |
Signal that an object is drained. More... | |
Private Member Functions | |
KvmVM (const KvmVM &vm) | |
KvmVM & | operator= (const KvmVM &vm) |
Private Attributes | |
System * | system |
int | vmFD |
KVM VM file descriptor. More... | |
bool | started |
Has delayedStartup() already been called? More... | |
bool | _hasKernelIRQChip |
Do we have in-kernel IRQ-chip emulation enabled? More... | |
long | nextVCPUID |
Next unallocated vCPU ID. More... | |
std::vector< MemorySlot > | memorySlots |
uint32_t | maxMemorySlot |
Friends | |
class | BaseKvmCPU |
Additional Inherited Members | |
Public Types inherited from SimObject | |
typedef SimObjectParams | Params |
Static Public Member Functions inherited from SimObject | |
static void | serializeAll (CheckpointOut &cp) |
Serialize all SimObjects in the system. More... | |
static SimObject * | find (const char *name) |
Find the SimObject with the given name and return a pointer to it. More... | |
Static Public Member Functions inherited from Serializable | |
static const std::string & | currentSection () |
Get the fully-qualified name of the active section. More... | |
static void | serializeAll (const std::string &cpt_dir) |
static void | unserializeGlobals (CheckpointIn &cp) |
Static Public Attributes inherited from Serializable | |
static int | ckptCount = 0 |
static int | ckptMaxCount = 0 |
static int | ckptPrevCount = -1 |
Protected Attributes inherited from SimObject | |
const SimObjectParams * | _params |
Cached copy of the object parameters. More... | |
Protected Attributes inherited from EventManager | |
EventQueue * | eventq |
A pointer to this object's event queue. More... | |
KVM VM container.
A KVM VM container normally contains all the CPUs in a shared memory machine. The VM container handles things like physical memory and to some extent interrupts. Normally, the VM API is only used for interrupts when the PIC is emulated by the kernel, which is a feature we do not use. However, some architectures (notably ARM) use the VM interface to deliver interrupts to specific CPUs as well.
VM initialization is a bit different from that of other SimObjects. When we initialize the VM, we discover all physical memory mappings in the system. Since AbstractMem::unserialize re-maps the guests memory, we need to make sure that this is done after the memory has been re-mapped, but before the vCPUs are initialized (KVM requires memory mappings to be setup before CPUs can be created). Normally, we would just initialize the VM in init() or startup(), however, we can not use init() since this is called before AbstractMem::unserialize() and we can not use startup() since it must be called before BaseKvmCPU::startup() and the simulator framework does not guarantee call order. We therefore call cpuStartup() from BaseKvmCPU::startup() instead and execute the initialization code once when the first CPU in the VM is starting.
KvmVM::KvmVM | ( | KvmVMParams * | params | ) |
Definition at line 294 of file vm.cc.
References Kvm::capNumMemSlots(), coalesceMMIO(), ArmISA::i, kvm, and maxMemorySlot.
|
private |
const KvmVM::MemSlot KvmVM::allocMemSlot | ( | uint64_t | size | ) |
Allocate a memory slot within the VM.
Definition at line 379 of file vm.cc.
References KvmVM::MemorySlot::active, maxMemorySlot, memorySlots, panic, X86ISA::size(), KvmVM::MemorySlot::size, and KvmVM::MemorySlot::slot.
Referenced by delayedStartup().
|
protected |
Allocate a new vCPU ID within the VM.
The returned vCPU ID is guaranteed to be unique within the VM. New IDs are allocated sequentially starting from 0.
Definition at line 560 of file vm.cc.
References nextVCPUID.
void KvmVM::coalesceMMIO | ( | Addr | start, |
int | size | ||
) |
Request coalescing MMIO for a memory range.
start | Physical start address in guest |
size | Size of the MMIO region |
Definition at line 464 of file vm.cc.
References DPRINTF, ioctl(), panic, and X86ISA::size().
Referenced by coalesceMMIO(), and KvmVM().
void KvmVM::coalesceMMIO | ( | const AddrRange & | range | ) |
Request coalescing MMIO for a memory range.
range | Coalesced MMIO range |
Definition at line 458 of file vm.cc.
References coalesceMMIO(), AddrRange::size(), and AddrRange::start().
long KvmVM::contextIdToVCpuId | ( | ContextID | ctx | ) | const |
Get the VCPUID for a given context.
Definition at line 540 of file vm.cc.
References ThreadContext::getCpuPtr(), System::getThreadContext(), and system.
Referenced by KvmKernelGicV2::readCpu(), KvmKernelGicV2::readDistributor(), KvmKernelGicV2::writeCpu(), and KvmKernelGicV2::writeDistributor().
|
protected |
VM CPU initialization code.
This method is called from BaseKvmCPU::startup() when a CPU in the VM executes its BaseKvmCPU::startup() method. The first time method is executed on a VM, it calls the delayedStartup() method.
Definition at line 334 of file vm.cc.
References delayedStartup(), and started.
Referenced by BaseKvmCPU::startup().
int KvmVM::createDevice | ( | uint32_t | type, |
uint32_t | flags = 0 |
||
) |
Create an in-kernel device model.
type | Device type (KVM_DEV_TYPE_xxx) |
flags | Creation flags (KVM_CREATE_DEVICE_xxx) |
Definition at line 515 of file vm.cc.
References ioctl(), panic, and X86ISA::type.
|
protected |
Create a new vCPU within a VM.
vcpuID | ID of the new CPU within the VM. |
Definition at line 548 of file vm.cc.
References ArmISA::fd, ioctl(), and panic.
Referenced by BaseKvmCPU::startup().
|
protected |
Delayed initialization, executed once before the first CPU starts.
This method provides a way to do VM initialization once before the first CPU in a VM starts. It is needed since some resources (e.g., memory mappings) can change in the normal SimObject::startup() path. Since the call order of SimObject::startup() is not guaranteed, we simply defer some initialization until a CPU is about to start.
Definition at line 344 of file vm.cc.
References allocMemSlot(), DPRINTF, PhysicalMemory::getBackingStore(), System::getPhysMem(), hack, AddrRange::interleaved(), panic, setupMemSlot(), AddrRange::size(), AddrRange::start(), and system.
Referenced by cpuStartup().
void KvmVM::disableMemSlot | ( | const MemSlot | slot | ) |
Disable a memory slot.
Definition at line 416 of file vm.cc.
References KvmVM::MemorySlot::active, memorySlots, KvmVM::MemSlot::num, and setUserMemoryRegion().
Referenced by freeMemSlot().
void KvmVM::freeMemSlot | ( | const MemSlot | slot | ) |
Free a previously allocated memory slot.
Definition at line 425 of file vm.cc.
References disableMemSlot(), memorySlots, KvmVM::MemSlot::num, and KvmVM::MemorySlot::size.
|
virtual |
Notify a child process of a fork.
When calling fork in gem5, we need to ensure that resources shared between the parent and the child are consistent. This method is intended to be overloaded to handle that. For example, an object could use this method to re-open input files to get a separate file description with a private file offset.
This method is only called in the child of the fork. The call takes place in a drained system.
Reimplemented from Drainable.
void KvmVM::setSystem | ( | System * | s | ) |
Initialize system pointer.
Invoked by system object.
Definition at line 532 of file vm.cc.
References panic_if(), ArmISA::s, and system.
Referenced by System::System().
void KvmVM::setTSSAddress | ( | Addr | tss_address | ) |
Setup a region of physical memory in the guest.
slot | KVM memory slot ID returned by allocMemSlot |
host_addr | Memory allocation backing the memory |
guest_addr | Address in the guest |
flags | Flags (see the KVM API documentation) |
Definition at line 407 of file vm.cc.
References KvmVM::MemorySlot::active, memorySlots, KvmVM::MemSlot::num, setUserMemoryRegion(), and KvmVM::MemorySlot::size.
Referenced by delayedStartup().
|
protected |
Setup a region of physical memory in the guest.
slot | KVM memory slot ID (must be unique) |
host_addr | Memory allocation backing the memory |
guest_addr | Address in the guest |
len | Size of the allocation in bytes |
flags | Flags (see the KVM API documentation) |
Definition at line 433 of file vm.cc.
References ioctl(), ArmISA::len, ArmISA::m, and panic.
Referenced by disableMemSlot(), and setupMemSlot().
|
friend |
|
private |
Do we have in-kernel IRQ-chip emulation enabled?
Definition at line 526 of file vm.hh.
Referenced by createIRQChip(), and hasKernelIRQChip().
Kvm* KvmVM::kvm |
Global KVM interface.
Definition at line 402 of file vm.hh.
Referenced by X86KvmCPU::dumpMSRs(), X86KvmCPU::getMsrIntersection(), KvmVM(), notifyFork(), BaseKvmCPU::startup(), X86KvmCPU::X86KvmCPU(), and ~KvmVM().
|
private |
Definition at line 542 of file vm.hh.
Referenced by allocMemSlot(), and KvmVM().
|
private |
Definition at line 541 of file vm.hh.
Referenced by allocMemSlot(), disableMemSlot(), freeMemSlot(), and setupMemSlot().
|
private |
|
private |
Has delayedStartup() already been called?
Definition at line 523 of file vm.hh.
Referenced by cpuStartup().
|
private |
Definition at line 517 of file vm.hh.
Referenced by contextIdToVCpuId(), delayedStartup(), and setSystem().
|
private |
KVM VM file descriptor.
Definition at line 520 of file vm.hh.
Referenced by ioctl(), notifyFork(), and ~KvmVM().