summaryrefslogtreecommitdiff
path: root/src/cpu/kvm/base.cc
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas@sandberg.pp.se>2015-11-27 14:52:10 +0000
committerAndreas Sandberg <andreas@sandberg.pp.se>2015-11-27 14:52:10 +0000
commit4f303785dc3001a8c952f19540e16a9b437278f2 (patch)
treeb03d09b88d2c5d5db402f4f6631976e0a82fda57 /src/cpu/kvm/base.cc
parenta91c1e69a880dd6eec3cc980801ea18ddcbe7c31 (diff)
downloadgem5-4f303785dc3001a8c952f19540e16a9b437278f2.tar.xz
kvm: Shutdown KVM and disconnect performance counters on fork
We can't/shouldn't use KVM after a fork since the child and parent probably point to the same VM. Knowing the exact effects of this is hard, but they are likely to be messy. We also disconnect the performance counters attached to the guest. This works around what seems to be a kernel bug where spurious SIGIOs get delivered to the forked child process. Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se> [sascha.bischoff@arm.com: Rebased patches onto a newer gem5 version] Signed-off-by: Sascha Bischoff <sascha.bischoff@arm.com> [andreas.sandberg@arm.com: Fatal if entering KVM in child process ] Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Diffstat (limited to 'src/cpu/kvm/base.cc')
-rw-r--r--src/cpu/kvm/base.cc28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/cpu/kvm/base.cc b/src/cpu/kvm/base.cc
index 32f94eca8..ea0f494e3 100644
--- a/src/cpu/kvm/base.cc
+++ b/src/cpu/kvm/base.cc
@@ -125,7 +125,7 @@ BaseKvmCPU::startup()
const BaseKvmCPUParams * const p(
dynamic_cast<const BaseKvmCPUParams *>(params()));
- Kvm &kvm(vm.kvm);
+ Kvm &kvm(*vm.kvm);
BaseCPU::startup();
@@ -363,6 +363,29 @@ BaseKvmCPU::drainResume()
}
void
+BaseKvmCPU::notifyFork()
+{
+ // We should have drained prior to forking, which means that the
+ // tick event shouldn't be scheduled and the CPU is idle.
+ assert(!tickEvent.scheduled());
+ assert(_status == Idle);
+
+ if (vcpuFD != -1) {
+ if (close(vcpuFD) == -1)
+ warn("kvm CPU: notifyFork failed to close vcpuFD\n");
+
+ if (_kvmRun)
+ munmap(_kvmRun, vcpuMMapSize);
+
+ vcpuFD = -1;
+ _kvmRun = NULL;
+
+ hwInstructions.detach();
+ hwCycles.detach();
+ }
+}
+
+void
BaseKvmCPU::switchOut()
{
DPRINTF(Kvm, "switchOut\n");
@@ -617,6 +640,9 @@ Tick
BaseKvmCPU::kvmRun(Tick ticks)
{
Tick ticksExecuted;
+ fatal_if(vcpuFD == -1,
+ "Trying to run a KVM CPU in a forked child process. "
+ "This is not supported.\n");
DPRINTF(KvmRun, "KVM: Executing for %i ticks\n", ticks);
if (ticks == 0) {