summaryrefslogtreecommitdiff
path: root/src/cpu
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2017-07-20 16:32:10 +0000
committerAndreas Sandberg <andreas.sandberg@arm.com>2017-08-01 16:20:24 +0000
commit9d6d3e5f7dd50e882a503ee4bb2ac7d9b8d21e30 (patch)
tree420084c370fc482015c2b00af84b0fe11be88b3a /src/cpu
parentc464f67955a131843cf232c5cd5430206e2494ab (diff)
downloadgem5-9d6d3e5f7dd50e882a503ee4bb2ac7d9b8d21e30.tar.xz
cpu, kvm: Fix deadlock issue when resuming a drained system
The KVM CPU sometimes needs to access devices when drain() is called. This typically happens on ARM when synchronizing devices that use the system register interface. When called from drain(), the event queue isn't locked since drain is called from the outside when the simulator isn't servicing any events. In such cases, performing a migration to the device's queue will unlock a mutex that isn't locked. This typically results in a deadlock when resuming the system since the lock will be in an undefined state. Change-Id: Ibdcc2e034e916a929124f297e72aae306cf66728 Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com> Reviewed-by: Curtis Dunham <curtis.dunham@arm.com> Reviewed-on: https://gem5-review.googlesource.com/4286 Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'src/cpu')
-rw-r--r--src/cpu/kvm/base.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cpu/kvm/base.cc b/src/cpu/kvm/base.cc
index 250c6a270..6ea99ce4a 100644
--- a/src/cpu/kvm/base.cc
+++ b/src/cpu/kvm/base.cc
@@ -358,6 +358,13 @@ BaseKvmCPU::drain()
return DrainState::Drained;
DPRINTF(Drain, "BaseKvmCPU::drain\n");
+
+ // The event queue won't be locked when calling drain since that's
+ // not done from an event. Lock the event queue here to make sure
+ // that scoped migrations continue to work if we need to
+ // synchronize the thread context.
+ std::lock_guard<EventQueue> lock(*this->eventQueue());
+
switch (_status) {
case Running:
// The base KVM code is normally ready when it is in the