diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-02-25 20:26:43 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-02-25 20:26:43 +0000 |
commit | f01e5389f8edfb79df55b8fef1e8bf5a30a93fb7 (patch) | |
tree | 7bb3b9216c9b56e588c8c1b54dabc763de1733f0 /pkg/sentry/platform | |
parent | 306bfa7fa8ec42d86f82c319720f3474528b1e1c (diff) | |
parent | 98b693e61b37a62f7b29ce1cab8b4c4c54fa044e (diff) |
Merge release-20200219.0-35-g98b693e (automated)
Diffstat (limited to 'pkg/sentry/platform')
-rw-r--r-- | pkg/sentry/platform/kvm/machine.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/pkg/sentry/platform/kvm/machine.go b/pkg/sentry/platform/kvm/machine.go index 8076c7529..f1afc74dc 100644 --- a/pkg/sentry/platform/kvm/machine.go +++ b/pkg/sentry/platform/kvm/machine.go @@ -329,10 +329,12 @@ func (m *machine) Destroy() { } // Get gets an available vCPU. +// +// This will return with the OS thread locked. func (m *machine) Get() *vCPU { + m.mu.RLock() runtime.LockOSThread() tid := procid.Current() - m.mu.RLock() // Check for an exact match. if c := m.vCPUs[tid]; c != nil { @@ -343,8 +345,22 @@ func (m *machine) Get() *vCPU { // The happy path failed. We now proceed to acquire an exclusive lock // (because the vCPU map may change), and scan all available vCPUs. + // In this case, we first unlock the OS thread. Otherwise, if mu is + // not available, the current system thread will be parked and a new + // system thread spawned. We avoid this situation by simply refreshing + // tid after relocking the system thread. m.mu.RUnlock() + runtime.UnlockOSThread() m.mu.Lock() + runtime.LockOSThread() + tid = procid.Current() + + // Recheck for an exact match. + if c := m.vCPUs[tid]; c != nil { + c.lock() + m.mu.Unlock() + return c + } for { // Scan for an available vCPU. |