From ec906e46c0f99ab4d134c1d7bd84b48ea0a78488 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Mon, 22 Jul 2019 13:27:13 -0700 Subject: kvm: fix race between machine.Put and machine.Get m.available.Signal() has to be called under m.mu.RLock, otherwise it can race with machine.Get: m.Get | m.Put ------------------------------------- m.mu.Lock() | Seatching available vcpu| | m.available.Signal() m.available.Wait | PiperOrigin-RevId: 259394051 --- pkg/sentry/platform/kvm/machine.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/sentry/platform/kvm/machine.go b/pkg/sentry/platform/kvm/machine.go index 679087e25..cc6c138b2 100644 --- a/pkg/sentry/platform/kvm/machine.go +++ b/pkg/sentry/platform/kvm/machine.go @@ -388,7 +388,10 @@ func (m *machine) Get() *vCPU { func (m *machine) Put(c *vCPU) { c.unlock() runtime.UnlockOSThread() + + m.mu.RLock() m.available.Signal() + m.mu.RUnlock() } // newDirtySet returns a new dirty set. -- cgit v1.2.3