diff options
author | Andrei Vagin <avagin@google.com> | 2019-07-22 13:27:13 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-07-22 13:28:16 -0700 |
commit | ec906e46c0f99ab4d134c1d7bd84b48ea0a78488 (patch) | |
tree | 87566b60696581390e2064994c9ef72668d162a0 /pkg | |
parent | a0a86bbb8250311211161337c0f9530b945450a3 (diff) |
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
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/sentry/platform/kvm/machine.go | 3 |
1 files changed, 3 insertions, 0 deletions
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. |