gem5  v21.1.0.2
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
gem5::KvmVM Class Reference

KVM VM container. More...

#include <vm.hh>

Inheritance diagram for gem5::KvmVM:
gem5::SimObject gem5::EventManager gem5::Serializable gem5::Drainable gem5::statistics::Group gem5::Named

Classes

class  MemorySlot
 Structures tracking memory slots. More...
 
struct  MemSlot
 

Public Member Functions

 KvmVM (const 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...
 
void enableKernelIRQChip ()
 Tell the VM and VCPUs to use an in-kernel IRQ chip for interrupt delivery. 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 gem5::SimObject
const Paramsparams () const
 
 SimObject (const Params &p)
 
virtual ~SimObject ()
 
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 regProbePoints ()
 Register probe points for this object. More...
 
virtual void regProbeListeners ()
 Register probe listeners for this object. More...
 
ProbeManagergetProbeManager ()
 Get the probe manager for this object. More...
 
virtual PortgetPort (const std::string &if_name, PortID idx=InvalidPortID)
 Get a port with a given name and index. 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 gem5::EventManager
EventQueueeventQueue () 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)
 This function is not needed by the usual gem5 event loop but may be necessary in derived EventQueues which host gem5 on other schedulers. More...
 
void setCurTick (Tick newVal)
 
 EventManager (EventManager &em)
 Event manger manages events in the event queue. More...
 
 EventManager (EventManager *em)
 
 EventManager (EventQueue *eq)
 
- Public Member Functions inherited from gem5::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 gem5::Drainable
DrainState drainState () const
 Return the current drain state of an object. More...
 
- Public Member Functions inherited from gem5::statistics::Group
 Group (Group *parent, const char *name=nullptr)
 Construct a new statistics group. More...
 
virtual ~Group ()
 
virtual void regStats ()
 Callback to set stat parameters. More...
 
virtual void resetStats ()
 Callback to reset stats. More...
 
virtual void preDumpStats ()
 Callback before stats are dumped. More...
 
void addStat (statistics::Info *info)
 Register a stat with this group. More...
 
const std::map< std::string, Group * > & getStatGroups () const
 Get all child groups associated with this object. More...
 
const std::vector< Info * > & getStats () const
 Get all stats associated with this object. More...
 
void addStatGroup (const char *name, Group *block)
 Add a stat block as a child of this block. More...
 
const InforesolveStat (std::string name) const
 Resolve a stat by its name within this group. More...
 
void mergeStatGroup (Group *block)
 Merge the contents (stats & children) of a block to this block. More...
 
 Group ()=delete
 
 Group (const Group &)=delete
 
Groupoperator= (const Group &)=delete
 
- Public Member Functions inherited from gem5::Named
 Named (const std::string &name_)
 
virtual ~Named ()=default
 
virtual std::string name () const
 

Public Attributes

Kvmkvm
 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 gem5::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)
 
KvmVMoperator= (const KvmVM &vm)
 

Private Attributes

Systemsystem
 
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< MemorySlotmemorySlots
 
uint32_t maxMemorySlot
 

Friends

class BaseKvmCPU
 

Additional Inherited Members

- Public Types inherited from gem5::SimObject
typedef SimObjectParams Params
 
- Static Public Member Functions inherited from gem5::SimObject
static void serializeAll (const std::string &cpt_dir)
 Create a checkpoint by serializing all SimObjects in the system. More...
 
static SimObjectfind (const char *name)
 Find the SimObject with the given name and return a pointer to it. More...
 
static void setSimObjectResolver (SimObjectResolver *resolver)
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints. More...
 
static SimObjectResolvergetSimObjectResolver ()
 There is a single object name resolver, and it is only set when simulation is restoring from checkpoints. More...
 
- Static Public Member Functions inherited from gem5::Serializable
static const std::string & currentSection ()
 Gets the fully-qualified name of the active section. More...
 
static void generateCheckpointOut (const std::string &cpt_dir, std::ofstream &outstream)
 Generate a checkpoint file so that the serialization can be routed to it. More...
 
- Protected Attributes inherited from gem5::SimObject
const SimObjectParams & _params
 Cached copy of the object parameters. More...
 
- Protected Attributes inherited from gem5::EventManager
EventQueueeventq
 A pointer to this object's event queue. More...
 

Detailed Description

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.

Definition at line 297 of file vm.hh.

Constructor & Destructor Documentation

◆ KvmVM() [1/2]

gem5::KvmVM::KvmVM ( const KvmVMParams &  params)

◆ ~KvmVM()

gem5::KvmVM::~KvmVM ( )
virtual

Definition at line 322 of file vm.cc.

References kvm, and vmFD.

◆ KvmVM() [2/2]

gem5::KvmVM::KvmVM ( const KvmVM vm)
private

Member Function Documentation

◆ allocMemSlot()

const KvmVM::MemSlot gem5::KvmVM::allocMemSlot ( uint64_t  size)

Allocate a memory slot within the VM.

Definition at line 391 of file vm.cc.

References gem5::KvmVM::MemorySlot::active, maxMemorySlot, memorySlots, panic, gem5::KvmVM::MemorySlot::size, and gem5::KvmVM::MemorySlot::slot.

Referenced by delayedStartup().

◆ allocVCPUID()

long gem5::KvmVM::allocVCPUID ( )
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.

Returns
ID of the new vCPU

Definition at line 572 of file vm.cc.

References nextVCPUID.

◆ coalesceMMIO() [1/2]

void gem5::KvmVM::coalesceMMIO ( Addr  start,
int  size 
)

Request coalescing MMIO for a memory range.

Parameters
startPhysical start address in guest
sizeSize of the MMIO region

Definition at line 476 of file vm.cc.

References DPRINTF, ioctl(), and panic.

Referenced by coalesceMMIO(), and KvmVM().

◆ coalesceMMIO() [2/2]

void gem5::KvmVM::coalesceMMIO ( const AddrRange range)

Request coalescing MMIO for a memory range.

Parameters
rangeCoalesced MMIO range

Definition at line 470 of file vm.cc.

References coalesceMMIO(), gem5::AddrRange::size(), and gem5::AddrRange::start().

◆ contextIdToVCpuId()

long gem5::KvmVM::contextIdToVCpuId ( ContextID  ctx) const

◆ cpuStartup()

void gem5::KvmVM::cpuStartup ( )
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 346 of file vm.cc.

References delayedStartup(), and started.

Referenced by gem5::BaseKvmCPU::startup().

◆ createDevice()

int gem5::KvmVM::createDevice ( uint32_t  type,
uint32_t  flags = 0 
)

Create an in-kernel device model.

Parameters
typeDevice type (KVM_DEV_TYPE_xxx)
flagsCreation flags (KVM_CREATE_DEVICE_xxx)
Returns
Device file descriptor

Definition at line 527 of file vm.cc.

References ioctl(), panic, and gem5::X86ISA::type.

◆ createVCPU()

int gem5::KvmVM::createVCPU ( long  vcpuID)
protected

Create a new vCPU within a VM.

Parameters
vcpuIDID of the new CPU within the VM.
Returns
File descriptor referencing the CPU.

Definition at line 560 of file vm.cc.

References gem5::ArmISA::fd, ioctl(), and panic.

Referenced by gem5::BaseKvmCPU::startup().

◆ delayedStartup()

void gem5::KvmVM::delayedStartup ( )
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 356 of file vm.cc.

References allocMemSlot(), DPRINTF, gem5::memory::PhysicalMemory::getBackingStore(), gem5::System::getPhysMem(), hack, gem5::AddrRange::interleaved(), panic, setupMemSlot(), gem5::AddrRange::size(), gem5::AddrRange::start(), and system.

Referenced by cpuStartup().

◆ disableMemSlot()

void gem5::KvmVM::disableMemSlot ( const MemSlot  slot)

Disable a memory slot.

Definition at line 428 of file vm.cc.

References gem5::KvmVM::MemorySlot::active, memorySlots, gem5::KvmVM::MemSlot::num, and setUserMemoryRegion().

Referenced by freeMemSlot().

◆ freeMemSlot()

void gem5::KvmVM::freeMemSlot ( const MemSlot  slot)

Free a previously allocated memory slot.

Definition at line 437 of file vm.cc.

References disableMemSlot(), memorySlots, gem5::KvmVM::MemSlot::num, and gem5::KvmVM::MemorySlot::size.

◆ notifyFork()

void gem5::KvmVM::notifyFork ( )
virtual

Notify a child process of a fork.

SimObjects are told that the process is going to be forked.

Forking is a process of splitting a process in to two processes, which is then used for multiprocessing.

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 gem5::Drainable.

Definition at line 332 of file vm.cc.

References kvm, vmFD, and warn.

◆ operator=()

KvmVM& gem5::KvmVM::operator= ( const KvmVM vm)
private

◆ setSystem()

void gem5::KvmVM::setSystem ( System s)

Initialize system pointer.

Invoked by system object.

Definition at line 544 of file vm.cc.

References panic_if, gem5::ArmISA::s, and system.

Referenced by gem5::System::System().

◆ setTSSAddress()

void gem5::KvmVM::setTSSAddress ( Addr  tss_address)

Setup a shared three-page memory region used by the internals of KVM.

This is currently only needed by x86 implementations.

Parameters
tss_addressPhysical address of the start of the TSS

Definition at line 492 of file vm.cc.

References ioctl(), and panic.

◆ setupMemSlot()

void gem5::KvmVM::setupMemSlot ( const MemSlot  slot,
void *  host_addr,
Addr  guest_addr,
uint32_t  flags 
)

Setup a region of physical memory in the guest.

Parameters
slotKVM memory slot ID returned by allocMemSlot
host_addrMemory allocation backing the memory
guest_addrAddress in the guest
flagsFlags (see the KVM API documentation)

Definition at line 419 of file vm.cc.

References gem5::KvmVM::MemorySlot::active, memorySlots, gem5::KvmVM::MemSlot::num, setUserMemoryRegion(), and gem5::KvmVM::MemorySlot::size.

Referenced by delayedStartup().

◆ setUserMemoryRegion()

void gem5::KvmVM::setUserMemoryRegion ( uint32_t  slot,
void *  host_addr,
Addr  guest_addr,
uint64_t  len,
uint32_t  flags 
)
protected

Setup a region of physical memory in the guest.

Parameters
slotKVM memory slot ID (must be unique)
host_addrMemory allocation backing the memory
guest_addrAddress in the guest
lenSize of the allocation in bytes
flagsFlags (see the KVM API documentation)

Definition at line 445 of file vm.cc.

References ioctl(), gem5::ArmISA::len, gem5::ArmISA::m, and panic.

Referenced by disableMemSlot(), and setupMemSlot().

Friends And Related Function Documentation

◆ BaseKvmCPU

friend class BaseKvmCPU
friend

Definition at line 299 of file vm.hh.

Member Data Documentation

◆ _hasKernelIRQChip

bool gem5::KvmVM::_hasKernelIRQChip
private

Do we have in-kernel IRQ-chip emulation enabled?

Definition at line 541 of file vm.hh.

Referenced by createIRQChip(), enableKernelIRQChip(), and hasKernelIRQChip().

◆ kvm

Kvm* gem5::KvmVM::kvm

◆ maxMemorySlot

uint32_t gem5::KvmVM::maxMemorySlot
private

Definition at line 557 of file vm.hh.

Referenced by allocMemSlot(), and KvmVM().

◆ memorySlots

std::vector<MemorySlot> gem5::KvmVM::memorySlots
private

Definition at line 556 of file vm.hh.

Referenced by allocMemSlot(), disableMemSlot(), freeMemSlot(), and setupMemSlot().

◆ nextVCPUID

long gem5::KvmVM::nextVCPUID
private

Next unallocated vCPU ID.

Definition at line 544 of file vm.hh.

Referenced by allocVCPUID().

◆ started

bool gem5::KvmVM::started
private

Has delayedStartup() already been called?

Definition at line 538 of file vm.hh.

Referenced by cpuStartup().

◆ system

System* gem5::KvmVM::system
private

Definition at line 532 of file vm.hh.

Referenced by contextIdToVCpuId(), delayedStartup(), and setSystem().

◆ vmFD

int gem5::KvmVM::vmFD
private

KVM VM file descriptor.

Definition at line 535 of file vm.hh.

Referenced by ioctl(), notifyFork(), and ~KvmVM().


The documentation for this class was generated from the following files:

Generated on Tue Sep 21 2021 12:27:45 for gem5 by doxygen 1.8.17