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
This commit is contained in:
Andrei Vagin 2019-07-22 13:27:13 -07:00 committed by gVisor bot
parent a0a86bbb82
commit ec906e46c0
1 changed files with 3 additions and 0 deletions

View File

@ -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.